RE: LOL, preg_match still not working.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, February 17, 2007 8:50 am, Beauford wrote:
> I've been over this a thousand times with various users on this list
> and
> escaping this and escaping that just doesn't matter.
>
> The error is that it thinks valid characters are invalid. In the case
> of the
> example I included, the ! and the period are invalid, which they
> should not
> be.
>
> The nocomments and invalidchars are constants.
>
> Thanks
>
>> -----Original Message-----
>> From: Ray Hauge [mailto:ray@xxxxxxxxxxxxxxxxxxxxxxx]
>> Sent: February 17, 2007 9:45 AM
>> To: Beauford
>> Cc: PHP
>> Subject: Re:  LOL, preg_match still not working.
>>
>> Maybe you just copied it wrong, but nocomments and
>> invalidchars are not
>> quoted, or they're constants.
>>
>> I don't think you have to, but you might need to escape some of the
>> characters (namely * and .) in your regex.  It's been a while, so
>> I'd
>> have to look it up.
>>
>> What's the error you are getting?
>>
>> Ray Hauge
>> Primate Applications
>>
>>
>> Beauford wrote:
>> > Hi,
>> >
>> > I previously had some issues with preg_match and many of
>> you tried to help,
>> > but the same  problem still exists. Here it is again, if
>> anyone can explain
>> > to me how to get this to work it would be great - otherwise
>> I'll just remove
>> > it as I just spent way to much time on this.
>> >
>> > Thanks
>> >
>> > Here's the code.
>> >
>> > 	if(empty($comment)) { $formerror['comment'] = nocomments;
>> > 	}
>> > 	elseif(!preg_match('|^[a-zA-Z0-9!?@#$%^&*();:_.\\\\ /\t-]+$|',

I believe you want:
'|^[a-z0-9!\\?@#\\$%^&\\*\\(\\);:_\\.\\\\ /\\t-]+$|'

In particular:
? means "maybe or maybe not the last PCRE expression", so the ! was
maybe or maybe not exluded.  Escape the ? with \\?

$ means "end", so escape that.

* means 0 or more, so escape that.

( and ) are used to capture the contents of a matching sub-expresson. 
Escape those.

. means ANY character, so escape that.

\t would work only inside of "" in PHP, not '', so you want PHP \\t to
turn into \t for PCRE which I think turns into a tab character... 
Actually, change the ' to " and use \t and then I'm *sure* it is a
tab.

I'm almost for sure that at least some of the above is utter nonsense
inside the [] where the "special" characters are not "special" at all,
but I can never remember the rules, and since '\\x' for a non-special
character turns into 'x' anyway, it doesn't "hurt" -- though it does
clutter up the PCRE for an expert, who wonders why the heck you did
that...

You should also re-read http://php.net/pcre and the two main pages
after that yet again.  I've read them 500 times, and some of it has
actually sunk in, so you're probably only got another 50 or so to go
before it works for you :-)

-- 
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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux