0

So, I have a string of text:

string with a bunch of links but i need to simply get rid of these <a href="a.domain.com">Title</a> string with more links and text

I need to get rid of everything from <a to a> where a.domain.com is present (its always the same domain) using PHP preg_replace.
It seems so simple but I can't figure this out >.< or find anywhere that explains regex :/

2 Answers 2

1

I always like this site for regexp: http://www.regular-expressions.info/ This isn't a full answer, but I would just match <a [...]>[...]</a> and make sure it's not greedy, so you don't end up tearing everything from the first occurance of <a [...]> all the way to the last </a>. This was recommended in another forum, you might want to give it a try as well:

$rev= preg_replace('/<a href="([^<]*)">([^<]*)<\/a>/', '', $_POST['rev']);
Sign up to request clarification or add additional context in comments.

Comments

0

If you're looking to keep what's inside the <a> tags, you can try the strip_tags() function.

If you want something more complicated, great tutorial for learning regular expressions is http://www.regular-expressions.info/

You can try something like

$no_tags = preg_replace('#<a (.*?)>(.*?)</a>#', '', $text);

but note that this will break if your tags are a more complex than the example you posted.

1 Comment

Nope, it just needs to delete the whole thing Site looks good tho

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.