2015-06-26 30 views
0
$string = "' ! ; • ,\ KarSho: ; • ;}"; 

在这里,我想删除下列字符去掉特定字符列表,从字符串PHP

$remove = array("'","!",";","•",",","\","}","{","[","]"); 

这也是输入。我想从上面的数组字符$ string。最后,我想串像,

KarSho:

+0

问题是反斜杠,“\”,“}”,“{”,“[”,“]”);尝试添加额外的“之前\标志.. 像”“\” –

+0

看看'str_replace()'解决方案(并且不要忘记逃避反斜杠) – Rizier123

+0

$ new_string = str_replace($ remove,“”,$ string ); – KarSho

回答

0

使用下面的代码:

$remove = array("'","!",";","•",",","\\","}","{","[","]"," "); 
$replace = array("","","","","","","","","","",""); 
$string = "' ! ; • ,\ KarSho: ; • ;}"; 
echo str_replace($remove,$replace,$string); 

您需要添加多一个\与\

0

您可以使用此代码

$string = "' ! ; • ,\ KarSho: ; • ;}"; 
echo $new_str = str_replace(str_split('\\/!;•,}:*?"<>|'), ' ', $string);