Wednesday 8 May 2019

php - Remove links where href is disallowed

I have some links like this:



legal


I want to remove all links that does not have "legallink.com" in it. But still keep the content. So the above input would output:



legal



It should work recursively through the links.



I found this regex that removes all links: /<\\/?a(\\s+.*?>|>)/, but I want it to keep links where href is legallink.com.



Can this be done with regex? Or should I use a DOM parser?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...