Re: regexp to match simple text not working
On Fri, 20 Jun 2008 21:54:57 +0200, Raistlin Majere <pedbessa@gmail.com>
wrote:
> On Jun 20, 4:50pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
>> On Fri, 20 Jun 2008 21:43:05 +0200, Raistlin Majere
>> <pedbe...@gmail.com>
>> wrote:
>>
>>
>>
>> > On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
>> >> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere
>> >> <pedbe...@gmail.com>
>> >> wrote:
>>
>> >> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/');
>> >> > // it accepts
>> >> > testtesttesttesttesttest
>>
>> >> > // it refuses
>> >> > testtest
>> >> > testtest
>> >> > testtest
>>
>> >> Most likely, because of \r.
>> >> An obvious solution would be:
>> >> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i');
>>
>> Please don't toppost.
>>
>> > it still says the message is invalid
>>
>> Not here it doesn't:
>> <?php
>> $variable = 'tasdtasd
>> asdasd
>> asdasd
>> asdasd';
>> $valid = '/^[a-z0-9,.!?\s]{1,10000}$/';
>> echo preg_match($valid, $variable) ? 'valid' : 'invalid';
>> ?>
>> Outputs:valid
>>
>> If you made sure the right regex & variable arrived at your function,
>> i'd
>> be interested in this output:
>> for($i = 0;$i < strlen($variable) ; $i++){
>> echo $variable[$i].'='.ord($variable[$i])."\n";}
> the output is
>
> ... \=92...
'\' is not valid, some code is escaping the \r & \n characters in your
$variable when you don't expect it. '\n' != "\n" Not something
addslashes() or magic_quotes would do, so the usual suspects for incorrect
escaping do not apply. Perhaps a premature mysql_(real_)escape_string?
Trace it back I'd say, examine the route your $variable goes, and aat what
point the newline character stops being a newline character.
--
Rik Wasmus
....spamrun finished
|