I have a list of html tags of the form
preg_replace('~<>~', ' ', $tag);, preg_replace("[<>]", ' ', $tag);, and preg_replace(array(">","<"), " ", $tag);
Based on your examples, the problem is that you are not using delimiters. You must use a delimiter (typically
/, but often
~). From the manual:
When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
Often used delimiters are forward slashes (
/), hash signs (
#) and tildes (
~). The following are all examples of valid delimited patterns.
So, your code could be:
$newString = preg_replace("/[<>]/", ' ', $tag);
Here's a demo, showing how it works.