Forum Moderators: coopster

Message Too Old, No Replies

PHP ereg_replace

removing <a href="http://etc>etc</a>

         

fwordboy

1:37 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



Hi can anyone heklp me with this? I basically need to reverse this ereg_replace statement


$comment = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>",$comment);

this code turns


hxxp://www.etc.com


<a href="http://www.etc.com">http://www.etc.com</a>

but I'd like to turn


<a href="http://www.etc.com">http://www.etc.com</a>

into


hxxp://www.etc.com

N.B. hxxp = http (i had to use this notation as the forum turns the exmaple into a link otherwise)

any suggestions? I guess I don't really understand the \\0's nor the [[:alpha:]], [[:space:]] symbols, so if someone could explain them better than the PHP manual, I'd be very grateful.

fwordboy

3:06 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



I did some searching and found the answer...


$comment = eregi_replace('<a .*href=("¦\')?([^ "\']*)("¦\')?.*>([^<]*)</a>', '\\2', $comment);

coopster

4:50 pm on Dec 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Glad you got it sorted, fwordboy. For anybody that comes along and copies that to use it in the future, don't forget to rekey the pipe symbols (¦) as the forum breaks the pipe.