Evo koda:
Code:
function CheckURL($text) {
$start='(www\.|http://|https://|ftp://|irc://)';
$url="[\w\?\~\-&=+;:%@#/,.]+[\w\?\~\-&=+;:%@#/]";
$text=preg_replace_callback("~(?<!]|=|/|\")($start$url)~is", 'url_callback', $text);
$text=preg_replace("~\[url(:nounderline)?=($url)](.+)\[/url]~iUs", '<a href="$2" target="_blank" rel="nofollow" $1>$3</a>', $text);
$text=preg_replace("~:nounderline>~iUs", 'style="text-decoration:none">', $text);
return $text;
}
function ForumParse($Text)
{
$Text = CheckURL($Text);
$Text = str_replace(array(':shit:',':g****:'), "<img src=\"smileys/shit.gif\" align=\"absmiddle\">", $Text);
$Text = str_replace(':cool:', "<img src=\"smileys/001_cool.gif\" align=\"absmiddle\">", $Text);
$Text = str_replace('xd', "<img src=\"smileys/xd.gif\" align=\"absmiddle\">", $Text);
// snip snip snip nebitno
return $Text;
}
function CheckURL($text) {
$start='(www\.|http://|https://|ftp://|irc://)';
$url="[\w\?\~\-&=+;:%@#/,.]+[\w\?\~\-&=+;:%@#/]";
$text=preg_replace_callback("~(?<!]|=|/|\")($start$url)~is", 'url_callback', $text);
$text=preg_replace("~\[url(:nounderline)?=($url)](.+)\[/url]~iUs", '<a href="$2" target="_blank" rel="nofollow" $1>$3</a>', $text);
$text=preg_replace("~:nounderline>~iUs", 'style="text-decoration:none">', $text);
return $text;
}
function ForumParse($Text)
{
$Text = CheckURL($Text);
$Text = str_replace(array(':shit:',':g****:'), "<img src=\"smileys/shit.gif\" align=\"absmiddle\">", $Text);
$Text = str_replace(':cool:', "<img src=\"smileys/001_cool.gif\" align=\"absmiddle\">", $Text);
$Text = str_replace('xd', "<img src=\"smileys/xd.gif\" align=\"absmiddle\">", $Text);
// snip snip snip nebitno
return $Text;
}
E sada, problem je - recimo - kod YouTube linkova... Ako link sadrži xd, tu se generiše smajli i ode sve u... vražju mater :) .... Pogubi se ceo kod...
Odavno sam se posvađao sa reg exp, tako da ne mogu da skontam neko jednostavno rešenje za ovo... Ako neko ima ideju, dobrodošla je. Hvala unapred :)
Putuj planeto, super smo se družili
nama je lepo, taman kako smo zaslužili!
nama je lepo, taman kako smo zaslužili!