Page 1 of 1
Find & Replace
Posted: Tue Aug 09, 2005 5:55 pm
by cbrian
I want to replace something like [link=
http://www.site.com]Go here![/link]
with <a href="http://www.site.com">Go here!</a>
Can I do that with Regular Expressions?
Posted: Tue Aug 09, 2005 6:50 pm
by feyd
yes. I'm pretty sure I posted the code for it a while ago in here somewhere....
well.. if you look at phpbb's bbcode.php file in the include folder, you'll find the info packed in there... There was a half-decent evilwalrus bbcode thing, but since the server is in limbo... you may be able to snag it via google cache or something.
Posted: Wed Aug 10, 2005 12:38 pm
by Chris Corbyn
Code: Select all
$string = '[link=http://www.site.com]Go here![/link]';
$anchor = preg_replace('/\[link=([^\]]+)\]([^\[]+)\[\/link\]/i', "<a href=\"$1\">$2</a>", $string);
Posted: Wed Aug 10, 2005 2:11 pm
by cbrian
Thanks, both of you!