jonnypixel
jonnypixel

Reputation: 327

Replace underscores with ampersands and hyphens with spaces

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.

Upvotes: 0

Views: 801

Answers (2)

Simon Hughes
Simon Hughes

Reputation: 3574

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

Upvotes: 1

jan
jan

Reputation: 2958

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

should work

Upvotes: 0

Related Questions