【发布时间】:2017-08-01 17:02:06
【问题描述】:
如何从脚本中删除/转义特殊字符
字符串是
echo $position="marketing & executive cum \ stock ";
Outputs are: marketing & executive cum \ stock
但我想要删除后的结果:
output: marketing executive cum stock
怎么可能?
有什么解决办法请帮忙..
【问题讨论】:
如何从脚本中删除/转义特殊字符
字符串是
echo $position="marketing & executive cum \ stock ";
Outputs are: marketing & executive cum \ stock
但我想要删除后的结果:
output: marketing executive cum stock
怎么可能?
有什么解决办法请帮忙..
【问题讨论】:
此问题可能与此问题重复 Remove all special characters from a string 所以请删除这个问题
【讨论】:
通过使用 preg_replace() 你可以做到这一点
function cleanString($string) {
$string = str_replace(array( '(', ')' ), '', $string);
return preg_replace('/[^A-Za-z0-9\-]/', ' ', $string);
}
echo cleanString('marketing & executive cum \ stock ');
【讨论】:
使用关注
$position="marketing & executive cum \ stock ";
echo preg_replace('/[^A-Za-z0-9\-\(\) ]/', '', $position);
【讨论】: