PDA

View Full Version : Help!! I need to put a preg_replace in PHPINCLUDE_END


Michael Morris
Mon 22nd Nov '04, 4:36pm
Hello. On a board I work on we need a "manacost" tag that turns this

1RG

into their graphical equivalents.

To date we've been doing this via javascript, but some goofs have been putting injections into the bbcode to cause trouble in the layout. A server side solution is therefore desirous.

This is the code I've written, but it's not working :(


//################ Do Mana Cost tag ######################

// Valid Characters to search for
$mana_find = array( 'w','u','b','r','g','t','x','y','z','1','2','3','4 ','5','6','7','8','9','0');

// Replacement Strings to insert
$mana_replace = array(
'<img src="http://www.wizards.com/images/symbols/Symbol_W_mana.gif" border="0" alt="W" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_U_mana.gif" border="0" alt="U" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_B_mana.gif" border="0" alt="B" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_R_mana.gif" border="0" alt="R" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_G_mana.gif" border="0" alt="G" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_T_mana.gif" border="0" alt="T" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_X_mana.gif" border="0" alt="X" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_Y_mana.gif" border="0" alt="Y" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_Z_mana.gif" border="0" alt="Z" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_1_mana.gif" border="0" alt="1" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_2_mana.gif" border="0" alt="2" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_3_mana.gif" border="0" alt="3" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_4_mana.gif" border="0" alt="4" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_5_mana.gif" border="0" alt="5" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_6_mana.gif" border="0" alt="6" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_7_mana.gif" border="0" alt="7" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_8_mana.gif" border="0" alt="8" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_9_mana.gif" border="0" alt="9" />',
'<img src="http://www.wizards.com/images/symbols/Symbol_0_mana.gif" border="0" alt="0" />'
);

// Now for the fun part - first we define our tag.
$manastring_find = '#\[mctwo\](.*)\[/mctwo\]#esiU';

// Now we define our replacement
$manastring_replace = "str_ireplace($mana_find, $mana_replace, '\\1');";

// Cross our fingers.
$output = preg_replace($manastring_find, $manastring_replace, $output);