How to replace special character '/' in a string in php. I just want replace only this special character, not all special character
For eg,
$str= 3/26, 5/15, 5/20, 5/26-5/28;
I want to replace / with -.
I want to replace'/' with something as passing this string to form a xml is giving error.
You would use str_replace(search, replace, subject)
ex:
$str = '3/26, 5/15, 5/20, 5/26-5/28';
$str = str_replace("/", '-', $str);
outputs:
3-26, 5-15, 5-20, 5-26-5-28
$str = '3/26, 5/15, 5/20, 5/26-5/28'; was being pulled from php-myadmin which is using html entities to get user input so when I decoded using function below
html_entity_decode(str_replace('/', '/', $sValue), ENT_COMPAT | ENT_QUOTES | ENT_HTML5);
and then used str_replace, I was able to get the result.