On Wed, 20 Oct 2004 01:02:12 -0500, Chris Ditty <cditty@xxxxxxxxx> wrote: > Hi all. I'm trying to do a little code snippets page for a site I am > working on. I figured it would be simple enough. I would do a > str_replace and replace the various html codes with the ascii > eqivulant. Unfortunately, it is not working as expected. Can anyone > help with this? > > This is what I am using. > $snippetCode = str_replace("\n", "<br>", $snippet['snippetCode']); > $snippetCode = str_replace("<", ">", $snippetCode); > $snippetCode = str_replace(">", "<", $snippetCode); > $snippetCode = str_replace("&", "&", $snippetCode); > > This is what is in $snippet['snippetCode']. > ?><pre><? print_r($ArrayName); ?></pre><? > > This is what is showing on the web page. > ?<>pre<>? print_r($ArrayName); ?<>/pre<>? Ok, first off there are builtin functions to do this kind of thing: http://www.php.net/htmlspecialchars http://www.php.net/nl2br Secondly, think about what your code is doing, and the order that it's doing the replacements. The first thing you're doing is replacing the newlines with <br> tags. The second and third things you're doing will disable all the tags including the <br> tags you've just inserted, by replacing '<' with < and '> with > html entities; The fourth thing you're doing is disabling the html entities by replacing '&' with & including the entities you've just inserted as steps two and three. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php