searchTerms functions

Hey guys: I’m trying to work on a function searchTerms() that takes a search string as a parameter and returns an array of all search terms in the string. Every token in the string is considered a search term, except for tokens wrapped in double quotation marks: these phrases should be treated as a single search term. You may assume that all tokens in the string are separated by exactly one space and that no search string has an odd number of double quotation marks, that is, all beginning quotation marks have a matching set of ending quotation marks. Here is what I have so far:
[php]function searchTerms($words)
{
$split = explode(" ", $words);
foreach ($split as &$values) {
if ($values == " ") {
return $values;
}
}
return $split;
}/php]

but it isn’t working, I get a notice saying it’s an array, which is not helpful.

Haven’t gotten to arrays in class yet? The function print_r will tell you what is in an array, so you can access those values.

Here you say " I’m trying to work on a function searchTerms() that takes a search string as a parameter and returns an array of all search terms "

Then you say “I get a notice saying it’s an array”.

Well, isnt that exactly what you asked for in the first sentence?

Also, you can’t do it with explode that way as it will explode anything inside the quotes.
So, your “Courtney Skinner” would become “Courtney and Skinner”…

You will need to rethink the problem some…

Sponsor our Newsletter | Privacy Policy | Terms of Service