Re: [PHP] quotemeta() question...

2005-02-14 Thread Richard Lynch
Jason Barnett wrote:
 Richard Lynch wrote:
 Steve Kaufman wrote:

Why does
  quotemeta(pat:1$WRW)
return
  pat:1
instead of
  pat:1\$WRW

What am I misunderstanding about quotemeta function?


 You usually would use quotemeta on data coming from the database, or the
 user, or externally, or, errr, basically things you haven't typed in to
 PHP, that you need to pass into Regular Expressions.

 In those cases, you've already got the $ (and other characters)
 successfully embedded in the string, but you want to escape them for
 whatever reason.

 A better example code would be:
 $string =
 'period.backslash\\plus+star*question?lbracket[rbracket]carat^lparen(rparen)dollar$';
 echo PRE, quotemeta($string), /PRE;


 Interesting aside... with the test string above, I noticed that
 backslash\\ only resolved to two backslashes.  I thought there would be
 4.  It seems that quotemeta will resolve \ and \\ to \\, \\\ and 
 resolve to , etc.

No, no, no.

FORGET quotemeta for a moment.

*BEFORE* the string ever GETS to quotemeta, PHP takes the characters you
typed and builds a string.

For PHP, \\ inside of apostrophes turns into a single \.

You Type:  Internal PHP string
'\\'   \
'\''   '
'' \\
\\   \
\   

It's absolutely crucial that you understand that PHP itself alters the \\
to \ lonnng before quotemeta enters the picture.

If you use just '\' in what you type, PHP is kinda stuck with just
assuming you meant '\\' and it runs with \ as its internal representation.

This is documented behaviour, but I consider it Bad Style.

So using \ or \\\ or any odd number of \ inside of apostrophes/quotes to
get a backslash in the internal PHP string is just plain bogus, if you ask
me. [shrug]

At any rate, quotemeta is *NOT* the thing that converts \ and \\ into \\.

PHP converts \ and \\ into a single \
quotemeta converts that single \ into \\

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] quotemeta() question...

2005-02-11 Thread Richard Lynch
Steve Kaufman wrote:
 Why does
   quotemeta(pat:1$WRW)
 return
   pat:1
 instead of
   pat:1\$WRW

 What am I misunderstanding about quotemeta function?

You usually would use quotemeta on data coming from the database, or the
user, or externally, or, errr, basically things you haven't typed in to
PHP, that you need to pass into Regular Expressions.

In those cases, you've already got the $ (and other characters)
successfully embedded in the string, but you want to escape them for
whatever reason.

A better example code would be:
$string =
'period.backslash\\plus+star*question?lbracket[rbracket]carat^lparen(rparen)dollar$';
echo PRE, quotemeta($string), /PRE;


-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] quotemeta() question...

2005-02-11 Thread Jason Barnett
Richard Lynch wrote:
Steve Kaufman wrote:
Why does
 quotemeta(pat:1$WRW)
return
 pat:1
instead of
 pat:1\$WRW
What am I misunderstanding about quotemeta function?

You usually would use quotemeta on data coming from the database, or the
user, or externally, or, errr, basically things you haven't typed in to
PHP, that you need to pass into Regular Expressions.
In those cases, you've already got the $ (and other characters)
successfully embedded in the string, but you want to escape them for
whatever reason.
A better example code would be:
$string =
'period.backslash\\plus+star*question?lbracket[rbracket]carat^lparen(rparen)dollar$';
echo PRE, quotemeta($string), /PRE;
Interesting aside... with the test string above, I noticed that
backslash\\ only resolved to two backslashes.  I thought there would be
4.  It seems that quotemeta will resolve \ and \\ to \\, \\\ and 
resolve to , etc.
--
Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins


signature.asc
Description: OpenPGP digital signature


Re: [PHP] quotemeta() question...

2005-02-11 Thread Jochem Maas
Jason Barnett wrote:
Richard Lynch wrote:
Steve Kaufman wrote:
Why does
 quotemeta(pat:1$WRW)
return
 pat:1
instead of
 pat:1\$WRW
What am I misunderstanding about quotemeta function?

You usually would use quotemeta on data coming from the database, or the
user, or externally, or, errr, basically things you haven't typed in to
PHP, that you need to pass into Regular Expressions.
In those cases, you've already got the $ (and other characters)
successfully embedded in the string, but you want to escape them for
whatever reason.
A better example code would be:
$string =
'period.backslash\\plus+star*question?lbracket[rbracket]carat^lparen(rparen)dollar$'; 

echo PRE, quotemeta($string), /PRE;
Interesting aside... with the test string above, I noticed that
backslash\\ only resolved to two backslashes.  I thought there would be
thats correct...
echo \\; // shows one backslash

4.  It seems that quotemeta will resolve \ and \\ to \\, \\\ and 
resolve to , etc.
--
Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins 

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


Re: [PHP] quotemeta() question...

2005-02-11 Thread Jason Barnett
Jochem Maas wrote:
...
A better example code would be:
$string =
'period.backslash\\plus+star*question?lbracket[rbracket]carat^lparen(rparen)dollar$';
echo PRE, quotemeta($string), /PRE;
Interesting aside... with the test string above, I noticed that
backslash\\ only resolved to two backslashes.  I thought there would be

thats correct...
echo \\; // shows one backslash
Well in the example above it was a single quote, not a double quote.
But either way... I would have thought there would be a 1:1 relationship
in the quotemeta translation (either quote all of them, or assume they
are all quoted already).

4.  It seems that quotemeta will resolve \ and \\ to \\, \\\ and 
resolve to , etc.
See above.  I would think (given my own common sense as well as the man
page for quotemeta) that there would be a quote added to each of these.
 But the results don't quite match this...
--
Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins


signature.asc
Description: OpenPGP digital signature


Re: [PHP] quotemeta() question...

2005-02-11 Thread Jochem Maas
Jason Barnett wrote:
Jochem Maas wrote:
...
A better example code would be:
$string =
'period.backslash\\plus+star*question?lbracket[rbracket]carat^lparen(rparen)dollar$'; 

echo PRE, quotemeta($string), /PRE;
Interesting aside... with the test string above, I noticed that
backslash\\ only resolved to two backslashes.  I thought there would be

thats correct...
echo \\; // shows one backslash
I should have been clearer:
echo \\; // shows one backslash
echo '\\'; // shows one backslash
the backslash is a metachar in both single and double quoted
strings so regardless of the quotes used in order to write a
literal backslash in a string you must 'backslash' it.
you still not with me?:
echo '\'; // does this parse?
so the output of metaquote() is correct.

Well in the example above it was a single quote, not a double quote.
But either way... I would have thought there would be a 1:1 relationship
in the quotemeta translation (either quote all of them, or assume they
are all quoted already).
it quotes them all AFAIT.


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


Re: [PHP] quotemeta() question...

2005-02-10 Thread Chris
Because it's parsing $WRW as a string, because of the double quotes. so 
you would need to do it like this:

quotemeta('pat:1$WRW')
to not let it parse any variables
or
quotemeta(pat:1\$WRW)
to not parse that particular variable
Steve Kaufman wrote:
Why does
 quotemeta(pat:1$WRW)
return
 pat:1
instead of
 pat:1\$WRW
What am I misunderstanding about quotemeta function? 

 

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