Jump to content


Photo

[php] The best way to parse the [url] tag


  • Please log in to reply
No replies to this topic

#1 Clement

Clement

    title available

  • Network Staff
  • 1,442 posts
  • Location:France
  • Projects:Various
  •  T3A Team Chamber Member
  • Division:Revora
  • Job:Developer

Posted 11 July 2008 - 10:45 AM

Hi everyone!

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.

Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users