note 37647 added to function.ctype-alpha
| From: | egypt at nmt dot edu | Date: | Fri, 21 Nov 2003 22:16:34 +0000 |
| Subject: | note 37647 added to function.ctype-alpha | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60772@lists.php.net to get a copy of this message | ||
Be careful with all of the ctype_* functions as they return true on the empty string, so the
following code will execute forever.
<?php
$string = "abc";
// infinite loop!
for($i = 4;ctype_alpha($string[$i]); $i++)
{
print $i;
}
?>
so always check the length of the string before doing something like that. i.e.:
while($i < strlen($string) && ctype_alpha($string[$i]))
----
Manual Page -- http://www.php.net/manual/en/function.ctype-alpha.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37647
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37647&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37647&report=yes
Search -- http://master.php.net/manage/user-notes.php