如何在單個函數中預先加載反斜槓中的某些字符?PHP對預定義字符集的addslashes
做了一堆str_replace
S的等效:
$text = "asdf[],.\?'";
$text = str_replace("'","\'", $text);
$text = str_replace("s","\s", $text);
$text = str_replace("[","\[", $text);
...etc...
我想在一個字符類通過像正則表達式,但不知道如何有preg_replace
前面加上反斜槓,而不是替換它。
$text = preg_replace("/['s\[]/","\{$var?}",$text);
我可以在數組中設置字符並循環它,但我似乎記得一個功能,只是這樣做。
BTW:請注意,'str_replace()函數''接受作爲array'參數也 – 2014-08-30 18:06:56