Valedol wrote:
Is there a mothod to check string`s length with regex or the only way is
using strlen?
I want string consisting of 4 digits
and check string with this code:
if (preg_match("/\d{4}/",$_POST[id]))
{ echo $_POST[id]; }
but preg_match returns true when string consists of 4 or more digits
Yes you can, but why do it this way? What advantage is it over the
following?
Given that this isn't a real intense regex, I don't know how much you
will save, but you could also do this.
if ( strlen(intval($_POST['id'])) == 4 ) {
echo $_POST['id'];
}
Not sure about speed, but it might be a little faster if you are looking
for performance.
Jim Lucas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php