tags:

views:

326

answers:

1

Hi there I was wondering whether someone know how to remove both the url and the link text from all anchor tags in a big paragraph of text. once remove if I could store them in an array for later use.

Im sure this is possible but I really struggle with regex.

Hopefully there is someone out there who has came across this before or who has some good knowledge on this.

Thank you

+1  A: 

Regex wasn't really designed to be a perfect html parser. Have you tried doing a simpleXML load string?

http://php.net/manual/en/function.simplexml-load-string.php

But for regex, check out these:

http://stackoverflow.com/questions/135151/whats-the-best-way-to-remove-br-tags-from-the-end-of-a-string

http://stackoverflow.com/questions/133571/how-to-convert-multiple-br-tag-to-a-single-br-tag-in-php

Citizen
this seems like one of those things where using regex would usually be fine as long as the HTML was well formed (i.e. there's no link-within-a-link). If there's formatting tags inside the link you could just strip them out after you grab the link text.
Carson Myers