FT3 Posted November 30, 2010 Report Share Posted November 30, 2010 <?php $replace_array = array( //BB CODES '[bb]' => '<B>', '[/bb]' => '</B>', //ANTI '<' => '<', '>' => '>', //SMILES ':)' => '<img src="http://www.krot.lv/engine/modules/mchat/smiles/smile-23.gif" alt=":)" />', ':(' => '<img src="http://sartira.net/engine/modules/mchat/smiles/smile-20.gif" alt=":(" />' ); $text_t = str_ireplace(array_keys($replace_array), $replace_array, $text_t); ?> kad teksts ir [bb]TEKSTS[/bb] rada <b>TEKSTS</b> bet vajag lai butu TEKSTS es zinu del ka tas ir del < = < un > = > , bet ka lai ustajsit ka [bb] šim kodam butu izņemums ? ! Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted November 30, 2010 Report Share Posted November 30, 2010 (edited) ceru ka sapratu pareizi.. labak lieto preg nevis str_rep $string = preg_replace("/\[b\](.*)\[\/b\]/Usi", "<b>\\1</b>", $string); $string = preg_replace("/\[u\](.*)\[\/u\]/Usi", "<u>\\1</u>", $string); $string = preg_replace("/\[i\](.*)\[\/i\]/Usi", "<i>\\1</i>", $string); $string = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*)\[\/color\]/Usi", "<span style=\"color:\\1\">\\2</span>", $string); $string = preg_replace("/\[size=(.*)\](.*)\[\/size\]/Usi", "<span style=\"font-size:\\1ex\">\\2</span>", $string); $string = preg_replace("/\[quote](.*)\[\/quote\]/Uis", "<div>Quote:</div><div style=\"border:solid 1px;\">\\1</div>", $string); $string = preg_replace("/\[quote=(.*)](.*)\[\/quote\]/Uis", "<div>Quote from: \\1</div><div style=\"border:solid 1px;\">\\2</div>", $string); Edited November 30, 2010 by EdgarsA Quote Link to comment Share on other sites More sharing options...
FT3 Posted November 30, 2010 Author Report Share Posted November 30, 2010 vari isak pateikt kur jaieraksta tekstu un ar ko lai izvada ? :) Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted November 30, 2010 Report Share Posted November 30, 2010 kā man besī, kad iedod rokās, bet pašam grūti pat iedziļināties .. $string = 'My name is [b]bolde text[/b], what is your name?'; $string = preg_replace("/\[b\](.*)\[\/b\]/Usi","<strong>\\1</b>",$string); echo $string; Quote Link to comment Share on other sites More sharing options...
briedis Posted November 30, 2010 Report Share Posted November 30, 2010 http://www.php.net/manual/en/ref.bbcode.php Quote Link to comment Share on other sites More sharing options...
FT3 Posted November 30, 2010 Author Report Share Posted November 30, 2010 EdgarsA tnx , kā man besī, kad iedod rokās, bet pašam grūti pat iedziļināties .. Vnk ilgu laiku biju aiznemts ar to 1 kodu :) Quote Link to comment Share on other sites More sharing options...
FT3 Posted November 30, 2010 Author Report Share Posted November 30, 2010 (edited) njam visu itka sapratu bet ka tgd ar tavu $string = preg_replace("/\[b\](.*)\[\/b\]/Usi", "<b>\\1</b>", $string); ustajsit smaidiņus ? Edited November 30, 2010 by FT3 Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted November 30, 2010 Report Share Posted November 30, 2010 (edited) $string = preg_replace("/:)/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:-)/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:(/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:-(/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:O/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:-O/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:D/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:-D/","<img src='smaidins.gif'>",$string); $string = preg_replace("/;)/","<img src='smaidins.gif'>",$string); $string = preg_replace("/;-)/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:P/","<img src='smaidins.gif'>",$string); $string = preg_replace("/:-P/","<img src='smaidins.gif'>",$string); Edited November 30, 2010 by EdgarsA Quote Link to comment Share on other sites More sharing options...
FT3 Posted November 30, 2010 Author Report Share Posted November 30, 2010 Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in C:\AppServ\www\forum\2.php on line 5 Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 2 in C:\AppServ\www\forum\2.php on line 6 Warning: preg_replace() [function.preg-replace]: Compilation failed: missing ) at offset 2 in C:\AppServ\www\forum\2.php on line 7 Warning: preg_replace() [function.preg-replace]: Compilation failed: missing ) at offset 3 in C:\AppServ\www\forum\2.php on line 8 Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in C:\AppServ\www\forum\2.php on line 13 Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 2 in C:\AppServ\www\forum\2.php on line 14 Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted November 30, 2010 Report Share Posted November 30, 2010 WTF - kapeec smaidinjiem vajag izmantot RegEx? Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 30, 2010 Report Share Posted November 30, 2010 $text = 'We love cookies! :)'; $smilies = array( ':)' => '<img src="images/smilies/happy.png />', ':(' => '<img src="images/smilies/sad.png />' // Etc.... ); $output = strTr( $text, $smilies ); Quote Link to comment Share on other sites More sharing options...
FT3 Posted December 1, 2010 Author Report Share Posted December 1, 2010 un ka lai apvienot tgd $output = strTr( $text, $smilies ); ar echo $string; ? ? Quote Link to comment Share on other sites More sharing options...
briedis Posted December 1, 2010 Report Share Posted December 1, 2010 un ka lai apvienot tgd $output = strTr( $text, $smilies ); ar echo $string; ? ? paeksperimentē, bitītmatos. Quote Link to comment Share on other sites More sharing options...
FT3 Posted December 1, 2010 Author Report Share Posted December 1, 2010 tnx sapludoju :) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted December 2, 2010 Report Share Posted December 2, 2010 Ja programmē, tad vēlams to darīt tā, ka pats saproti ko tur dari. Savādāk tā būs bezmērķīga simbolu copy -> paste'ošana. =( 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.