Hi guys,

I'm working on a project and wanted to know if there is a good / trusted way to break a string apart into words. I want to get all the words in a string that will be used in a mysql query.

I tested with str_word_count but it breaks up the string into characters like (a, b) if there are no words in the string.

Thanks in advance.

Member Avatar for RudyM

split() or explode()? Or did I misunderstand your question?

Hi Rudy,

I tried using split & explode but you have to have a delimiter (" ", | ",", | "+", | ".",) and I want the splitting to be more dynamic with out me using delimiters.

Let say I have a string (This isa string + that_needs to be, split.into words), do do the splitting here will be a nightmare and I want something that will be more dynamic.

Not sure if it make's sense what I'm asking?

I'm pulling data from a database table then I want to break the data up into words / varalbes and then re-use those in the next MySQL query for a more refined search.

Thanks

preg_split('/\PL+/u', $string, -1, PREG_SPLIT_NO_EMPTY);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.