Jump to content
php.lv forumi

replace array


FT3

Recommended Posts

<?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 ? !

Link to comment
Share on other sites

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 by EdgarsA
Link to comment
Share on other sites


$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 by EdgarsA
Link to comment
Share on other sites

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

Link to comment
Share on other sites

$text = 'We love cookies! :)';

$smilies = array(

':)' => '<img src="images/smilies/happy.png />',
':(' => '<img src="images/smilies/sad.png />'
// Etc....

);

$output = strTr( $text, $smilies );

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...