View Full Version : Php str_replace

02-25-2007, 09:00 PM
Hi there,

I have a comments system, where people can post comments. I have disabled html and the <> tags, so i am making my own bord code. At the moment, people can add images by putting in image url here. This is the code i have that lets people do this...

$imgtag = array("", "");
$replacetag = array("<img src='","' id='usr'>");
$newcomment = str_replace($imgtag, $replacetag, $row2[comments]);

$postedcomment = wordwrap($newcomment,83, " ", 1);

My question is, i want to add in another tag so that people can make their text bold by putting........This text will be bold without the 1 in the tag - (I have put the 1 in the b tag because if i dont, then this forum board code will acctually make the text bold because that is the tag that they use).

This is the code i have so far...

$boldtag = array("", "");
$replacetagbold = array("<b>","</b>");
$newcomment2 = str_replace($boldtag, $replacetagbold, $row2[comments]);
Now, i have tried so many ways to link it up with the other code, like merge them together, but everything i have tried fails. How can i merge the bold replace with the img replace so that people can use both [img] and [b] tags???


02-25-2007, 11:15 PM
Use regular expressions. Search the forums, there have been lots of posts regarding this exact topic.