Where可以找到使用preg_replace时必须转义的所有字符的列表。我在数组$ESCAPE_CHARS中列出了我认为的其中三个。我还缺少什么。
我需要这个,因为我将在提交表格时进行预替换。
也就是
$ESCAPE_CHARS = array("#", "^", "[");
foreach ($ESCAPE_CHARS as $char) {
$_POST{"string"} = str_replace("$char", "''$char", $_POST{"string"});
}
$string = $_POST{"string"};
$test = "string of text";
$test = preg_replace("$string", "<b>$string</b>", $test);
谢谢!
您可以使用preg_quote():
$keywords = '$40 for a g3/400';
$keywords = preg_quote($keywords, '/');
print $keywords;
// '$40 for a g3'/400