RE: [PHP] Escaping dollar sign???
| From: | Matt Schroebel | Date: | Wed, 23 Oct 2002 18:08:17 +0000 |
| Subject: | RE: [PHP] Escaping dollar sign??? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-121142@lists.php.net to get a copy of this message | ||
How about:
$statement = 'if ($a == 1) { some_func(); }';
echo $statement;
In the double quoted string $a was replaced by it's value.
> -----Original Message-----
> From: Shawn McKenzie [mailto:nospam@mckenzies.net]
> Sent: Wednesday, October 23, 2002 2:05 PM
> To: php-general@lists.php.net
> Subject: [PHP] Escaping dollar sign???
>
>
> 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(); }
>