Escaping dollar sign???
| From: | Shawn McKenzie | Date: | Wed, 23 Oct 2002 18:04:38 +0000 |
| Subject: | Escaping dollar sign??? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-121141@lists.php.net to get a copy of this message | ||
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