RE: [PHP] Escaping dollar sign???

From: Date: Wed, 23 Oct 2002 18:20:00 +0000
Subject: RE: [PHP] Escaping dollar sign???
Groups: php.general 
Request: Send a blank email to php-general+get-121149@lists.php.net to get a copy of this message
> -----Original Message----- > From: Shawn McKenzie [mailto:nospam@mckenzies.net] > Sent: Wednesday, October 23, 2002 2:19 PM > To: php-general@lists.php.net > Subject: Re: [PHP] Escaping dollar sign??? > > > 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. Yes you can, either break out and double quote them or escape them, whichever is easier at the time. $statement = 'if ($a == 1) { some_func(\'some text\'); }'; Lookout as newlines will not convert either. Try: echo '\n'; > > > 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(); } > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#121149) next »