Search code examples
phpmysqlstrposmatch-against

Find a space in string and append character after


I am constructing a search query and would like to search the words seperatly if multiple are entered, currently i am doing:

   MATCH (P.`content`) AGAINST ('+$term' IN BOOLEAN MODE)

But if the term had multiple words i would like $term to display like '+multiple +word +term'

So i need to check for a space in the string and append the + after the space. I know i can use strpos($string, " ") to find the/A space but wont this stop after the first space it finds? would a preg_match be better?

Also am i right in thinking that substr_replace($term, '+', $pos, 0); will work to insert the character? but again will only be able to handle one space not multiple


Solution

  • Was over thinking it $term = str_replace(" ", " +", $term); did what i need, thanks to M A SIDDIQUI