note 37647 modified in function.ctype-alpha by hholzgra

From: Date: Mon, 24 Jan 2005 00:13:13 +0000
Subject: note 37647 modified in function.ctype-alpha by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-83847@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. (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])) --was-- 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])) http://php.net/manual/en/function.ctype-alpha.php

« previous php.notes (#83847) next »