开发者

prepend the plus(+) symbol and append asterix(*) symbol to words in a query in PHP

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜