php - Regular expression for <a> tag replacement -
I am new to regular expressions, but I am trying to learn about it. I want to remove the tag of an HTML text, and just want to leave the internal text. Something like this:
Basic: Ads & lt; A href = "http://www.google.es" & gt; Google & lt; / A & gt; Advertising & lt; A href = "http://www.bing.com" & gt; Bing & lt; / A & gt; Result: Google AdSense Bing
I am using this code:
$ patterns = array ("/ (& lt; a href = \ "[A -z0- 9.: _ \ - \ /] {1,} \" & gt;) / i "," /
It works, but I do not know whether this code is more efficient or more readable.
Can I improve the code anyway?
In your case, PHP should be done in the exact same way without any regular expressions. If you want to touch only a specific tag (some strip_tags ()
can not by default), then there is a function in it.
In general, regexes are not suitable, it is better to use DOM parser to parse HTML or any of these
Comments
Post a Comment