I'm almost there, but I have one remaining problem. Here's my code
PHP Code:
//################ 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">',
'<img src="http://www.wizards.com/images/symbols/Symbol_U_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_B_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_R_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_G_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_T_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_X_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_Y_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_Z_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_1_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_2_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_3_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_4_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_5_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_6_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_7_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_8_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_9_mana.gif">',
'<img src="http://www.wizards.com/images/symbols/Symbol_0_mana.gif">'
);
// Now for the fun part - first we define our tag.
$manastring_find = "#\[mctwo\](.*)\[/mctwo\]#esiU";
// Cross our fingers.
$output = preg_replace($manastring_find, 'str_replace($mana_find, $mana_replace, $1)', $output);
My problem is that the prereq is now searching the string twice. I'd like to be able to have border="0" alt="X" in the img name, and be able to include lower case w, u, b, r, g, x, y, z, and t; but when I do the thing screws up royally because it tries to replace those characters whereever they occur within the img tag. This sets up an infinite loop.
How do I stop it from searching through the string twice?