Re: [PHP] Miserable escape string problem

2006-10-05 Thread John Wells

On 10/5/06, [EMAIL PROTECTED] [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.



First up:
http://uk2.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

Excerpt:
Again, if you try to escape any other character, the backslash will be
printed too! Before PHP 5.1.1, backslash in \{$var} hasn't been
printed.

Then:
http://uk2.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

Excerpt:
Since you can't escape '{', this syntax will only be recognised when
the $ is immediately following the {. (Use {\$ to get a literal
{$).

Does that help?

HTH,
John W

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Miserable escape string problem

2006-10-05 Thread intra_test

John Wells wrote:


Excerpt:
Since you can't escape '{', this syntax will only be recognised when
the $ is immediately following the {. (Use {\$ to get a literal
{$).

Does that help?


Not really, John.
===
$var1 = 1; $var2 = 2;
print({\$var1: $var2});
===

will output {$var1: 2}. I need this output {1: 2}.
What I need is an escape character for the {, but it looks like
PHP doesn't have any.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Miserable escape string problem

2006-10-05 Thread Richard Lynch
On Thu, October 5, 2006 11:37 am, [EMAIL PROTECTED] wrote:
 John Wells wrote:
 
 Excerpt:
 Since you can't escape '{', this syntax will only be recognised when
 the $ is immediately following the {. (Use {\$ to get a literal
 {$).

 Does that help?

 Not really, John.
 ===
 $var1 = 1; $var2 = 2;
 print({\$var1: $var2});
 ===

 will output {$var1: 2}. I need this output {1: 2}.
 What I need is an escape character for the {, but it looks like
 PHP doesn't have any.

$curly = '{';
echo $curly$var1: $var2};

-- 
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] Miserable escape string problem

2006-10-05 Thread intra_test

Richard Lynch wrote:

$curly = '{';
echo $curly$var1: $var2};


Horrendous workaround.


Google Kreme wrote:
 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.
I suggest you bring yourself up to speed on what escaping really means.
Your suggestion under no circumstances escaping.


Actually, PHP Documentation does mention it:
Since you can't escape '{', this syntax

See here(thanks go John Wells for posting about it):
http://uk2.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

Now you may go on a rampage about what escaping means, but honestly, I
don't want to hear about it.




Richard Lynch wrote:
 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.

 :-)
Bingo. That is what I am trying to do. But I am not allowed since there
is no escaping for this thing.


Thanks all for the replies. My intention was to bring to light YA PHP
design problem. Looks to me like I didn't really succeed, but at least
it's out.


Regards

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Miserable escape string problem

2006-10-05 Thread Dave Goodchild

Is this really worth all the keystrokes? Do we not have any more valuable
ways to spend our time?

On 06/10/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


Richard Lynch wrote:
 $curly = '{';
 echo $curly$var1: $var2};

Horrendous workaround.


Google Kreme wrote:
 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.
I suggest you bring yourself up to speed on what escaping really means.
Your suggestion under no circumstances escaping.


Actually, PHP Documentation does mention it:
Since you can't escape '{', this syntax

See here(thanks go John Wells for posting about it):

http://uk2.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

Now you may go on a rampage about what escaping means, but honestly, I
don't want to hear about it.




Richard Lynch wrote:
 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.

 :-)
Bingo. That is what I am trying to do. But I am not allowed since there
is no escaping for this thing.


Thanks all for the replies. My intention was to bring to light YA PHP
design problem. Looks to me like I didn't really succeed, but at least
it's out.


Regards

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
http://www.web-buddha.co.uk


Re: [PHP] Miserable escape string problem

2006-10-05 Thread intra_test

Dave Goodchild wrote:
Is this really worth all the keystrokes? Do we not have any more 
valuable ways to spend our time?


Good point Dave. But on the wrong side.

By counting all the keystrokes the PHP developers have to type extra
for code like this:
{{$foo}: {$bar}}
'{'.$var1.': '.$var2.'}'
etc.

vs. such code
\{$foo: $bar}

and actually not accounting for the ease of reading and assimilating
such code, guess what's better? Ramp about it? Or try rise the problem?

ciao

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Miserable escape string problem

2006-10-05 Thread Robert Cummings
On Fri, 2006-10-06 at 01:35 +0200, [EMAIL PROTECTED] wrote:
 Dave Goodchild wrote:
  Is this really worth all the keystrokes? Do we not have any more 
  valuable ways to spend our time?
 
 Good point Dave. But on the wrong side.
 
 By counting all the keystrokes the PHP developers have to type extra
 for code like this:
 {{$foo}: {$bar}}


 '{'.$var1.': '.$var2.'}'

My prefered way is definitely this one. It's simple really, let me sing
it for you...

in, out... in, out... shake it all about... ;)

When adding variable data to strings, by using the in, out (shake it all
about method), the technique is identical whether you are using object
properties, nested array fields, simple variables, functions, constants.
That's right, I said one way fits every last one of them, try that with
your precious interpolation :B Interestingly, it also happens to be the
fasted method from a processor standpoint :)

Cheers,
Rob.


 etc.
 
 vs. such code
 \{$foo: $bar}
 
 and actually not accounting for the ease of reading and assimilating
 such code, guess what's better? Ramp about it? Or try rise the problem?

I have a PHP coprocessor embedded in my skull, it's all easy to read...
well as long as the braces are properly formatted anyways *haha* ;)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php