I want to replace everything except the following:
spaces
(
)
numbers
AND
OR
Here's my current code which almost works except it allows any of the letters from ANDOR to be left.
I want it to only leave the full word AND or O开发者_开发百科R otherwise strip it.
$string = preg_replace("/[^()ANDOR0-9 ]/", "", $string);
Any ideas what code I need?
$a1 = array("AND", "OR");
$a2 = array("&","|");
$result = str_replace($a2, $a1, preg_replace("/[^()0-9 &|]/", "", str_replace($a1, $a2, preg_replace("/[^()ANDOR0-9 ]/", "", $string))));
Not very elegant, but it works.
精彩评论