2017-03-11 61 views
1

如何刪除/轉義特殊系統字符來回腳本如何刪除speacial字符,如:&)( /從字符串使用PHP

字符串的是

echo $position="marketing & executive cum \ stock "; 

Outputs are: marketing & executive cum \ stock 

但我想刪除後的結果? :?

output: marketing executive cum stock 

它是如何更多鈔票

有任何解決方案,請幫助..

+0

可能的複製[正則表達式淨化(PHP)](http://stackoverflow.com/questions/3022185/regular-expression-sanitize-php) – v010dya

回答

1

使用的preg_replace(),你可以做到這一點

function cleanString($string) { 
    $string = str_replace(array('(', ')'), '', $string); 
    return preg_replace('/[^A-Za-z0-9\-]/', ' ', $string); 
} 

echo cleanString('marketing & executive cum \ stock '); 
+0

感謝它的作品,但我想刪除)(這些也請所以建議.. – Anuveester

+0

檢查工作很好再次感謝 – Anuveester

+0

@ Muthu17:這將是偉大的:https://eval.in/752861獲得單個空間 – C2486

1

使用後

$position="marketing & executive cum \ stock "; 

echo preg_replace('/[^A-Za-z0-9\-\(\) ]/', '', $position); 
+0

它的工作,但想要刪除)(也是這樣如何可能 – Anuveester

+0

@Anuveester:從正則表達式中刪除'\(\)'將工作 – C2486

+0

preg_replace('/ [^ A-Za-z0-9 \ ] /','',$ position); – Karthik

相關問題