[PHP] Re: Miserable escape string problem
[EMAIL PROTECTED] wrote: Using this string: "{$var1: $var2}" of course it doesn't work as some might expect. But why in the name of [whatever, too many to list] doesn't this one below work? "\{$var1: $var2}" If \ is an escape character why does it also appear in the string output? Why does the above \ escape {$var1 and not only the {? Miserable. because {$var1} is a valid syntactical construct? try this instead: '{'.$var1.': '.$var2.'}' Kae -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Miserable escape string problem
Well Kae, if you reply 3 times let me also reply you once. What you try to suggest is a workaround. A workaround should not be needed for such a basic thing. Ever. The point is, \ should escape only the {, just like it does when you escape a variable like this "\$var1" In this case, \ only escapes the $. Even then, why does it output the \? Try this: = $var1 = 1; $var2 = 2; print("\{$var1: $var2}"); = It will output: \{1: 2} Why the \? Isn't it an escape character. If you try to get me thinking that this is normal behaviour, let's agree to disagree. PS: I'd like to see an insider comment on this, eventually explain the thought behind this implementation. Kae Verens wrote: because {$var1} is a valid syntactical construct? try this instead: '{'.$var1.': '.$var2.'}' Kae -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
The escaping works fine for me.. using the code: $var1 = 1; $var2 = 3; echo "\$var1: $var2"; print "\$var1: $var2"; print ("\$var1: $var2"); All output: $var1: 3 as expected. Is there a way to re-define the escape character or something? I can't think of why that wouldn't escape the $ properly. = = = Original message = = = Well Kae, if you reply 3 times let me also reply you once. What you try to suggest is a workaround. A workaround should not be needed for such a basic thing. Ever. The point is, \ should escape only the , just like it does when you escape a variable like this "\$var1" In this case, \ only escapes the $. Even then, why does it output the \? Try this: = $var1 = 1; $var2 = 2; print("\$var1: $var2"); = It will output: \1: 2 Why the \? Isn't it an escape character. If you try to get me thinking that this is normal behaviour, let's agree to disagree. PS: I'd like to see an insider comment on this, eventually explain the thought behind this implementation. Kae Verens wrote: > because $var1 is a valid syntactical construct? > > try this instead: > ''.$var1.': '.$var2.'' > > Kae ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
Sorry tg, you missed the whole point. Read again. The escaping works fine for me.. using the code: $var1 = 1; $var2 = 3; echo "\$var1: $var2"; print "\$var1: $var2"; print ("\$var1: $var2"); All output: $var1: 3 as expected. Is there a way to re-define the escape character or something? I can't think of why that wouldn't escape the $ properly -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
Let's look at your original message: Using this string: "$var1: $var2" of course it doesn't work as some might expect. It works exactly as expected. Within double-quotes, things like variables get evaluated. In this case $var1 and $var2 will be replaced by their values. That's what's "expected". But why in the name of [whatever, too many to list] doesn't this one below work? "\$var1: $var2" If \ is an escape character why does it also appear in the string output? Why does the above \ escape $var1 and not only the ? In the test I did, it behaves exactly as it's expected to behave. "\" escapes the next character. Or in the case of some characters, there may be more than one after the \ that get interpreted. For example "\x41" is hexdecimal value 41. The \$var1 above is indicating you want to display a "$" literally and not interpret it despite being contained within double-quotes. The "var1" part, not having a "$" on the front of it, doesn't get interpretted as anything and is output literally as "var1". Maybe rephrasing the question would help because reading your original message doesn't tell me anything except that there's a communication problem. Unless "\$var1: $var2" does NOT output "$var1: ", then everything is functioning as designed and expected. -TG = = = Original message = = = Sorry tg, you missed the whole point. Read again. > The escaping works fine for me.. using the code: > > $var1 = 1; > $var2 = 3; > > echo "\$var1: $var2"; > print "\$var1: $var2"; > print ("\$var1: $var2"); > > All output: > > $var1: 3 > > as expected. > > Is there a way to re-define the escape character or something? I can't think > of why that wouldn't escape the $ properly > ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
[EMAIL PROTECTED] wrote: > Let's look at your original message: > > Using this string: > "$var1: $var2" > of course it doesn't work as some might expect. Either your mail client is broken, or you're misquoting him on purpose: Using this string: "{$var1: $var2}" of course it doesn't work as some might expect. To address the original question, a backslash does not escape the brace. Are you wanting the variables to be evaluated? Here's an example that demonstrates both: Hope that helps. Chris -- Chris Shiflett http://shiflett.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
Either your mail client is broken, or you're misquoting him on purpose: Using this string: "{$var1: $var2}" of course it doesn't work as some might expect. Thanks Chris, I already emailed him on private 'cause I didn't want to clutter the list unneeded. To address the original question, a backslash does not escape the brace. Are you wanting the variables to be evaluated? Here's an example that demonstrates both: It occurs to me I wasn't clear enough, although one could have figure it out. By using this: === $var1 = 11; $var2 = 22; outputstringfunction("{$var1: $var2}"); //hypothetical code === I'd like to have the output as "{11: 22}". By using "{{$var1}: {$var2}}" it works just fine, but this is a mess, I can't live with. What I am using now is "{ $var1: $var2}", better. I guess what I am asking for is more or less uninteresting to most of the PHP developers(many are just coders, really... for the difference search the net) that eat up whatever offered, so I might just rest my case. So, yes, there is no escaping for { in PHP and that would be it. Hope that helps. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
[EMAIL PROTECTED] wrote: > I'd like to have the output as "{11: 22}". My previous example demonstrates that: > echo "{{$foo}: {$bar}}"; Chris -- Chris Shiflett http://shiflett.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
On 05 Oct 2006, at 10:50 , [EMAIL PROTECTED] wrote: So, yes, there is no escaping for { in PHP and that would be it. So what is "{{$var1} : {$var2}}" ?? -- MEGAHAL: within my penguin lies a torrid story of hate and love. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
Unneeded clutter, yes.. but I owe you an apology and since the mistake was public, I'll make the apology public as well. I use a 'universal' email checker called ePrompter. It does text-only, no HTML, so it filters out HTML messages, but have never had a problem with it filtering out braces, brackets, or any stuff like that. Even HTML tags used in text messages make it through ok I believe. Anyway, my apology for my screwup. See what you get for trusting technology? :) Best of luck! -TG = = = Original message = = = > Either your mail client is broken, or you're misquoting him on purpose: > > Using this string: > "$var1: $var2" > of course it doesn't work as some might expect. Thanks Chris, I already emailed him on private 'cause I didn't want to clutter the list unneeded. ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
Google Kreme wrote: On 05 Oct 2006, at 10:50 , [EMAIL PROTECTED] wrote: So, yes, there is no escaping for { in PHP and that would be it. So what is "{{$var1} : {$var2}}" ?? A workaround. ciao -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
Google Kreme wrote: > So what is "{{$var1} : {$var2}}" Within a quoted string, you can surround variable names with braces for clarity. This is especially helpful for situations like this, where the rest of the string interferes with syntax. A more common example is when a variable name is immediately followed by an alphabetic character: When you try this, PHP thinks $animals is the name of the variable. If you want to be clear that the name of the variable is $animal, you can use braces: $string = "I like {$animal}s."; So, I don't consider this a workaround. It's clean, intuitive syntax for exactly these types of scenarios. Hope that helps. Chris -- Chris Shiflett http://shiflett.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
On Thu, October 5, 2006 10:55 am, [EMAIL PROTECTED] wrote: > The point is, \ should escape only the {, just like > it does when you escape a variable like this "\$var1" > In this case, \ only escapes the $. The whole thing with {} inside a string has always struck me as a total hack to fix something that wasn't broken in the first place, and I can never get it to do what I want. "Don't use it" is my solution. :-) -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Miserable escape string problem
On 05 Oct 2006, at 11:37 , Chris Shiflett wrote: Google Kreme wrote: So what is "{{$var1} : {$var2}}" Within a quoted string, you can surround variable names with braces for clarity. This is especially helpful for situations like this, where the rest of the string interferes with syntax. Heh. It was a rhetorical question. He said there was no way to escape the {'s Of course there is... that was my point. -- No man is free who is not master of himself -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php