Jump to content

[SOLVED] Remove all links and everything in between


raku

Recommended Posts

Hi,

 

I am trying to remove all links and everything in between them from a string.

 

preg_replace("/<a\b[^>]*>(.*?)<\/a>/i", "", $string);

 

only works if the <a> tag and the other text are right next to each other or separated by spaces, it doesn't work for line breaks.

 

For example.. it successfully removes everything in this string (sorry the closing tags of the hyperlinks was translated by the forum into [/url]):

 

<a href="test"> test test test</a>

 

But does nothing for this string:

<a href="test">

    test test test test

</a>

 

My guess is that I need something for line breaks in the preg_replace, but I'm not sure what it is. Any idea how I can fix this?

 

Thanks!

 

edit: I tried adding "/n" to the regexp, but then everything got removed, even stuff before the <a> tag.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.