Re: str_replace problem
| From: | Silvio Porcellana | Date: | Wed, 20 Oct 2004 08:14:49 +0000 |
| Subject: | Re: str_replace problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199854@lists.php.net to get a copy of this message | ||
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? What is that you are actually expecting?
This is what I am using. $snippetCode = str_replace("\n", "<br>", $snippet['snippetCode']); nl2br() [http://php.libero.it/manual/en/function.nl2br.php]
$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<>? This is what you are asking PHP to do.Actually - to achieve this - it would be better to use the 'htmlspecialchars()' function [http://php.libero.it/manual/en/function.htmlspecialchars.php] Anyway, probably I didn't understand what you want from your code... Cheers! Silvio Porcellana