[thelist] PHP - str_replace problem

Maximillian Schwanekamp lists at neptunewebworks.com
Wed Oct 20 02:46:05 CDT 2004


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?
><snip />
>If anyone can help, it would be appreciated.  Also, if you have a
>quick and dirty code colorer, I would appreciate that.
>  
>
The usual way to quote code snippets is to use one of PHP's handy 
functions, htmlspecialchars() or htmlentities().  There's also 
highlight_string() and highlight_file() for displaying source code with 
simple syntax coloring.  Note that the two highlight_ functions by 
default output rough markup, with font tags and all.  But you did say 
quick and dirty!
<?php
$escaped = htmlentities($snippet['snippetCode']);
echo "<code><pre>$escaped</pre></code>";
?>
OR
<?php
$escaped = highlight_string($snippet['snippetCode'],1);
echo "<code><pre>$escaped</pre></code>";
?>

HTH!
Maximillian Von Schwanekamp
Dynamic Websites and E-Commerce
NeptuneWebworks.com <http://www.neptunewebworks.com/>
voice: 541-302-1438
fax: 208-730-6504



More information about the thelist mailing list