I wonder how I can prepend the plus(+) symbol and append asterix(*) symbol to words in a query?
For instance, the query 'Car Bar'
should b开发者_运维百科e '+Car* +Bar*'
php> echo preg_replace("/\w+/", '+\0*', "Car Bar")
+Car* +Bar*
Either explode()
a string a prepend and append your symbols on string parts and later implode()
them, or use regular expressions.
$string = preg_replace("/\w+/", "+$0*", $string);
精彩评论