开发者

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

开发者 https://www.devze.com 2023-03-25 09:59 出处:网络
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(\

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

精彩评论

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