You are here: Re: [PHP] preg_match « PHP « IT news, forums, messages
Re: [PHP] preg_match

Posted by "Richard Lynch" on 10/19/31 11:24

On Fri, August 19, 2005 7:03 am, Matthew Weier O'Phinney wrote:
> * John Nichel <john@kegworks.com> :
>> Richard Lynch wrote:
>> > On Thu, August 18, 2005 2:50 pm, Jon wrote:
>> > > preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single,
>> > > $from_invoice);
>> >
>> > I would recommend using \\s instead of \s -- While \s doesn't have
>> any
>> > meaning in PHP strings, so PHP just figures you must have meant
>> \\s
>> <snip>
>>
>> But in perl type regex's, the \s is a space. Without testing it, I
>> don't think \\s would match what the OP was looking for (I *think*

But Perl isn't going to *SEE* \\s !!!

PHP is going to *EAT* \\ and make \ out of it.

That's why \ is an escape character in PHP.

It's also an escape character in Perl/PCRE.

Some days I think PHP's escape character should have been | or
something, just so this topic wouldn't come up every damn month.

>> it
>> would match '\s'). However, I don't understand why the OP is
>> looking
>> for a space " ", followed by a space "\s", followed by multiple
>> spaces
>> "\s+"....a \s{1,} would have done all that just fine.
>
> But in double quotes, \ is seen as an escape, and could be interpreted
> differently. Probably the better way to do this would be:
>
> $pattern = '/Charges\s+' . $total . ' x ([^\s]*)/si';
> preg_match_all($pattern, $single, $from_invoice);

But in single quote \ is ALSO an escape, albeit for a smaller number
of characters -- 2, to be precise.

I don't care if you use single or double quotes, if you want PCRE to
get \s, then PHP should be using \\s inside of them.

PHP "eats" a \\ and spits out \ and then PCRE "sees" \s which is what
you want.

This is true for both single and double quotes.

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация