Re: Re: LOL, preg_match still not working.
| From: | Al | Date: | Tue, 20 Feb 2007 13:19:58 +0000 |
| Subject: | Re: Re: LOL, preg_match still not working. | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-249080@lists.php.net to get a copy of this message | ||
I sorry, what is the variable text in the message. Is there any text that is always constant, e.g., "This is a test of the emergency broadcast system."
Inherently, your object seems obvious. The problem is that you are not providing enough examples.
Show us some that you want to match AND some that should not match.
Beauford wrote:
Read my original email for the example string, I have referred to this in every one of my emails. It's even at the bottom of this one. -----Original Message----- From: Al [mailto:news@ridersite.org] Sent: February 18, 2007 10:35 AM To: php-general@lists.php.net Subject: [PHP] Re: LOL, preg_match still not working. If you want help, you must provide some example text strings that are to be matched. You keep posting your pattern and that's the problem. Beauford wrote:Mails been down since this morning (sorry, that's yesterday morning). Anyway, not sure if this went through, so here it is again. ------ The bottom line is I want to allow everything in the expression andnothingelse. The new line does not seem to be an issue - I can put as manyreturnsas I want, but as soon as I add some punctuation, it falls apart. As I said before, the ! and the period from my original example arereportedas invalid - as they are in the expression they should be valid, I'm sure there are other examples as well, but you can see what the problem is. IfItake out the ! and period from my example and leave the new lines in, it works fine. Thanks-----Original Message----- From: Gregory Beaver [mailto:greg@chiaraquartet.net] Sent: February 17, 2007 12:21 PM To: Beauford Cc: PHP Subject: [PHP] Re: LOL, preg_match still not working. Beauford wrote:Hi, I previously had some issues with preg_match and many ofyou tried to help,but the same problem still exists. Here it is again, ifanyone can explainto me how to get this to work it would be great - otherwiseI'll just removeit 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php