Re: Ereg problems

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

 



Hi

  As I said before I don't use posix regexes (i.e. ereg), as they're not
binary safe and can be much slower than the PCRE versions. the PCRE
equivalent of what you want is:

if (preg_match("/^[-A-Za-z0-9_' ]+$/", $string)}:
  echo "string valid";
else:
  echo "string invalid";
endif;

  The "A-Za-z0-9_" can be simplified to "\w" meaning any 'word'
character.
  The slashes '/' are required as delimeters around a regex with PCRE.
  The '^' and '$' anchor to beginning and end. This makes sure you're
testing the whole string not just a part of it, otherwise it would match
up to the first invalid character but still make a match.

  I use this kind of test frequently myself, so I know it is possible
and fairly simple to do.


Niel

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux