2015-06-26 31 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);