Re: Escaping dollar sign???

From: Date: Wed, 23 Oct 2002 18:16:04 +0000
Subject: Re: Escaping dollar sign???
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-121146@lists.php.net to get a copy of this message
Use single quotes. Shawn McKenzie wrote:
To eval() the $statement string below, I've found that I need to escape the $. str_replace() is not working for this. Any ideas??? $statement = "if ($a == 1) { some_func(); }"; echo $statement; Produces (this is not what I want): if ( == 1) { some_func(); } Manual escaping : $statement = "if (\$a == 1) { some_func(); }"; echo $statement; Produces (this is what I want, great!!!): if ($a == 1) { some_func(); } String replace: $statement = "if ($a == 1) { some_func(); }"; $statement = str_replace("$", "\$", $statement); echo $statement; Produces (what am I missing???): if ( == 1) { some_func(); } TIA -Shawn


« previous php.general (#121146) next »