[英]How to replace special character ' /' in php with another special character
How to replace special character '/' in a string in php. 如何在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; $ 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. 我想用一些东西替换'/',因为将这个字符串传递给xml会产生错误。
You would use str_replace(search, replace, subject)
您将使用
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
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. 是从使用HTML实体获取用户输入的Php-MyAdmin中提取的。
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. 然后使用
str_replace
,我能够得到结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.