Since a moment I'm working on a bbcode that I use on several website... and I have some problem with the [ url ] tag, because the user has three ways to insert an url:
- http://revora.net - [url]http://revora.net[/url] - [url="http://revora.net"]Revora[/url]So I tried several things, but nothing works correctly, my last attempt was with the preg_replace_callback function
function link_bbcode($m) { if (isset($m[4]) AND preg_match('#http://[a-z0-9._/-]+#i', $m[4])) { if (isset($m[2]) AND !empty($m[2])) { $var1 = $m[3]; $var2 = $m[4]; } else { $var1 = $m[4]; $var2 = $m[4]; } return '<a href="'. $var1 .'>'. $var2 .'</a>'; } } $text = preg_replace_callback('!([url(=(.+))?])?(.+)([/url])?!isU', 'link_bbcode', $text);
So if you could help me, any idea is welcome!
Edited by TheDeadPlayer, 11 July 2008 - 10:50 AM.