hi...
i need a statement that removes anchor tags.... actually, one that replaces them with a space. the entire anchor tag ie : from <a to </a>.
i used eregi_replace ... but no matter how i write the match pattern .... it either removes all the html or none of it .....
thanks -m
Lotsa different ways to do this. Here's one
<? $item = "Blah, blah, blah:<a href=\"something\">Something</a>:blah, blah"; $start = explode("<a",$item); $end = explode("</a>",$item); $newString=$start[0].$end[1]; ?>
That just splits it up into arrays. Doesn't require the small overhead of the regular expression engine.
$text = preg_replace("!<a.*?>.*?</a>!is", ' ', $text);
To use ereg_replace that would be:
$text = eregi_replace("<a[^>]*>([^<]|<[^/]|</[^a]|</a[^>])*</a>", " ", $text);
I think, because POSIX regexps don't have ungreedy matching.
Knew some regex guy would come around with the answer....
those regexp guys are pretty smart....
i also tried a while loop..... but i like clean simple code (one statement).
where can i find a regexp tutorial? and what is the "si" at the end of the preg_replace pattern?