anonīms Posted August 25, 2010 Report Share Posted August 25, 2010 (edited) googlēju, googlēju, bet visur tiek izmantots [url=*]*[/url] šāds variants man neder, jo nepieciešams [url][/url] pašlaik kods ir šāds: function forum_text($text) { $bbcode = array("<", ">", "[img=", "]", "[b]", "[/b]", "[u]", "[/u]", "[i]", "[/i]", '[url]', "[/url]", '"]'); $htmlcode = array("<", ">", "<br /><img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", '<a href="', "</a>", '">'); $newtext = str_replace($bbcode, $htmlcode, $text); $newtext = nl2br($newtext); return $newtext; } Kā dabūt gatavu to ? EDIT: '/\[url\](.*?)\[\/url\]/is' vs '<a href="$1">$1</a>', šādi ar neiet Edited August 25, 2010 by anonīms Quote Link to comment Share on other sites More sharing options...
Леший Posted August 25, 2010 Report Share Posted August 25, 2010 (edited) Paprovē '<a href="', '">Links uz ārējo resursu</a>', Protams, ka ar regex neies, jo tu izmanto str_replace(). Edited August 25, 2010 by Леший Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 25, 2010 Author Report Share Posted August 25, 2010 Njā, šādi iet, bet ir atkal BET. 1kārt nepieciešams ir arī redzams šis links (www adrese) un 2kārt, kas notiek, ja users met linku bez http://? pagaidām ir tā, ka liekot www.adrese.lv tiek iets uzadresi www.adrese.lv/forums/www.adrese.lv Quote Link to comment Share on other sites More sharing options...
Леший Posted August 25, 2010 Report Share Posted August 25, 2010 http://lv.php.net/manual/en/function.preg-replace-callback.php Quote Link to comment Share on other sites More sharing options...
Kavacky Posted August 25, 2010 Report Share Posted August 25, 2010 (edited) $text = preg_replace( "#\[url\](?:http:\/\/)?(.+?)\[/url\]#is", "<a href=\"http://$1\">$1</a>", $text ); Edited August 25, 2010 by Kavacky Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 25, 2010 Author Report Share Posted August 25, 2010 Dabuju gatavu jau šādi function forum_text($str) { $bb = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url\](.*?)\[\/url\]/is' ); $replace = array( "<strong>$1</strong>", "<i>$1</i>", "<u>$1</u>", "<br /><img src='$1' alt='' /><br />", "<a href='http://$1' title='$1' target='_blank' rel='nofollow'>$1</a>" ); $str = preg_replace($bb,$replace,$str); return $str; } Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 25, 2010 Author Report Share Posted August 25, 2010 Vienīgi, kas notiek, ja lietotājs iemet nevis www.adrese.lv, bet gan http://adrese.lv tad sanāk, ka ir http://http://adrese.lv Quote Link to comment Share on other sites More sharing options...
Леший Posted August 25, 2010 Report Share Posted August 25, 2010 http://lv.php.net/manual/en/function.preg-replace-callback.php Quote Link to comment Share on other sites More sharing options...
Kavacky Posted August 25, 2010 Report Share Posted August 25, 2010 Vienīgi, kas notiek, ja lietotājs iemet nevis www.adrese.lv, bet gan http://adrese.lv tad sanāk, ka ir http://http://adrese.lv Izlasi rūpīgi manu iepriekšējo postu un izdomā, kas sanāk. Ja nesanāk izdomāt, notestē. Quote Link to comment Share on other sites More sharing options...
marcis Posted August 25, 2010 Report Share Posted August 25, 2010 Ja tu tā akli taisies repleisot, tad labāk iztiec vispār bez bbcode :) [url]www.google.com" onclick="alert(document.cookie)[/url] Quote Link to comment Share on other sites More sharing options...
Kavacky Posted August 25, 2010 Report Share Posted August 25, 2010 Pirms pārējām teksta transformācijām iemet klāt htmlspecialchars un viss bumbās. Quote Link to comment Share on other sites More sharing options...
anonīms Posted August 25, 2010 Author Report Share Posted August 25, 2010 Tātad, ja pareizi sapratu, tad normāls variants (+ bez ievainojumiem) būtu šāds: function forum_text($str) { $str = htmlspecialchars($str); $str = preg_replace( "#\[url\](?:http:\/\/)?(.+?)\[/url\]#is", "<a href=\"http://$1\">$1</a>", $str ); $str = preg_replace( "#\[img\](?:http:\/\/)?(.+?)\[/img\]#is", "<img src=\"http://$1\" />", $str ); $str = preg_replace( "#\[b\](.+?)\[/b\]#is", "<strong>$1</strong>", $str ); $str = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>$1</i>", $str ); $str = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>$1</u>", $str ); return $str; } Labojiet, ja maldos Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.