note 37647 deleted from function.ctype-alpha by nlopess
| From: | nlopess@php.net | Date: | Tue, 25 Jul 2006 11:16:53 +0000 |
| Subject: | note 37647 deleted from function.ctype-alpha by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115138@lists.php.net to get a copy of this message | ||
Note Submitter: egypt at nmt dot edu
----
Be careful with all of the ctype_* functions as they return true on the empty string, so the
following code will execute forever.
(see also http://bugs.php.net/30945)
<?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]))