Page 1 of 1

regular expression. stripping anchor tag

Posted: Wed Oct 26, 2005 1:38 pm
by alvinphp
Anyone know how to strip the anchor tag information so that it only shows the display name? I have two examples below along with what I want it to be...

<a href='test.php?id=5A'>red</a> -> red
<a href='test.php?id=1B1'>blue</a> -> blue

I could probably figure it out if I was given 5 hours, but I am hoping someone here knows. :D

Posted: Wed Oct 26, 2005 2:11 pm
by Jenk

Code: Select all

$text = preg_replace('/<a[^<>]*?>(.+?)<\/a>/i', "$1", $text);
However, that can be easily exploited by nesting anchors.

This should be in the Regex forum.

Posted: Wed Oct 26, 2005 2:44 pm
by alvinphp
Thanks Jen, just what I needed. And yes, I should of put this in the regex forum. :?

I haven't worked with regex in over a year, it is all coming back to me now. Just need a little push start! I just created 4 more regex's.