Reputation: 5831
I have a variable which has this structure:
$catname = 'this-is-my-category';
How can I strip the "-" and get:
$catname = 'this is my category';
Upvotes: 2
Views: 1822
Reputation: 145472
For character-wise replacing the ideal function is strtr
:
$catname = strtr($catname, "-", " ");
This makes less effort if you later decide to replace e.g. underscores too.
Upvotes: 1
Reputation: 32031
Use the str_replace function like this:
$catname = str_replace('-', ' ', $catname);
This would replace every occurence of -
with in your string.
Upvotes: 6