Re: Escaping dollar sign???
| From: | Shawn McKenzie | Date: | Wed, 23 Oct 2002 18:18:50 +0000 |
| Subject: | Re: Escaping dollar sign??? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-121147@lists.php.net to get a copy of this message | ||
Ahhh... Works great! Thanks!
I'm a newbie so this may be elementary but...the caveat is, I can't have any
more ' in the string.
This is bad:
$statement = 'if ($a == 1) { some_func('some text'); }';
This is ok:
$statement = 'if ($a == 1) { some_func("some text"); }';
Thanks a million!!!
-Shawn
"Matt Schroebel" <MSchroebel@hsus.org> wrote in message
news:D4DB668A680B2549AE977FB0B193E2E80373D6@email.hsus.org...
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(); }
>