Re: str_replace problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Oct 20, 2004, at 1:02 AM, Chris Ditty 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("<", "&gt;", $snippetCode);

< is actually less than

$snippetCode = str_replace(">", "&lt;", $snippetCode);

and > is greater than. Don't know if this makes a difference to you.

$snippetCode = str_replace("&", "&amp;", $snippetCode);

This is what is in $snippet['snippetCode'].
?><pre><? print_r($ArrayName); ?></pre><?

This is what is showing on the web page.
?&lt;&gt;pre&lt;&gt;? print_r($ArrayName); ?&lt;&gt;/pre&lt;&gt;?

If anyone can help, it would be appreciated.  Also, if you have a
quick and dirty code colorer, I would appreciate that.

Thanks
Chris

Like the others have said, consider using htmlspecialchars().

Have fun!
~Philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux