Re: LOL, preg_match still not working.
| From: | Gregory Beaver | Date: | Sat, 17 Feb 2007 17:20:58 +0000 |
| Subject: | Re: LOL, preg_match still not working. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248979@lists.php.net to get a copy of this message | ||
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-]+$|',
> $comment)) {
> $formerror['comment'] = invalidchars;
> }
>
> This produces an error, which I believe it should not.
>
> Testing 12345. This is a test of the emergency broadcast system.
>
> WAKE UP!!!!!!
Hi,
Your sample text contains newlines. If you wish to allow newlines,
instead of " \t" you should use the whitespace selector "\s"
<?php
$comment = 'Testing 12345. This is a test of the emergency broadcast system.
WAKE UP!!!!!!';
if(!preg_match('|^[a-zA-Z0-9!?@#$%^&*();:_.\\\\\s/-]+$|', $comment)) {
echo 'oops';
} else {
echo 'ok';
}
?>
Try that code sample, and you'll see that it says "ok"
What exactly are you trying to accomplish with this preg_match()? What
exactly are you trying to filter out? I understand you want to
eliminate "invalid characters" but why are they invalid? I ask because
there may be a simpler way to solve the problem, if you can explain what
the problem is.
Thanks,
Greg