What am I doing wrong? I'm trying to read a string of text and convert {! winxp.gif !} into <a href="winxp.gif">.
Here's the code:
$text_string="This is a test string. {! winxp.gif left !} Here is some more of the string. {! testimg.jpg right !} And here is the rest of the string."; $new_text = preg_replace("#{!(.?)(.?)!}#","<img src=\"\1\" align=\"\2\">", $text_string); echo "$new_text";
$text_string="This is a test string. {! winxp.gif left !} Here is some more of the string. {! testimg.jpg right !} And here is the rest of the string.";
$new_text = preg_replace("#{!(.?)(.?)!}#","<img src=\"\1\" align=\"\2\">", $text_string);
echo "$new_text";
What I get is this:
This is a test string. <img src="" align=""> Here is some more of the string. <img src="" align=""> And here is the rest of the string.
I've tweaked this a thousand times trying to get it right. Can someone help?
Well, after two hours of fiddling, I solved my own problem. Needed $s in the replacement string. Correct code is:
$new_text = preg_replace("#{! (.?) (.?) !}#","<img src=\"$1\" align=\"$2\">", $text_string);