开发者

Replace underscores with ampersands and hyphens with spaces

开发者 https://www.devze.com 2023-04-12 02:31 出处:网络
I have a mysql table that 开发者_开发百科contains words joined by underscores and also words joined by hyphens.

I have a mysql table that 开发者_开发百科contains words joined by underscores and also words joined by hyphens.

example: Engineering-Service_Civil-Geotech

I am able to replace the underscore with an ampersand and add a space on either side, but im stuck at how to replace the hyphen with one blank space as well.

$cleanCat =  str_replace( '_', ' & ', $Cat);
echo $cleanCat; 

The result of the above code gives me one solution but not both:

example: Engineering-Service & Civil-Geotech

Do i have to use a different command to achieve this?

thanks in advance.


$cleanCat =  str_replace('-', ' ', str_replace( '_', ' & ', $Cat));


str_replace( '-', ' ', $Cat); or str_replace( '-', ' ', $Cat);

should work

0

精彩评论

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

关注公众号