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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.