note 63924 deleted from function.substr by bjori

From: Date: Tue, 04 Apr 2006 09:21:12 +0000
Subject: note 63924 deleted from function.substr by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-107270@lists.php.net to get a copy of this message
Note Submitter: andy at arakka dot co dot th Reason: useless ---- WARNING - You would think that substr( $string, 0, $length) would return the first $length characters of $string, or $string if it's less than $length. Nope. substr( '', 0, $length) returns False, not ''. If a later function tests for type, you'll get is_bool(), not is_string(). The specs say that substr() returns FALSE if strlen() <= $start. Arguably it should return FALSE if strlen() < $start, and "" if strlen() == $start. I had to write this function: <?php function SubString( $String, $Start, $Length ) { if ( strlen( $String ) == $Start ) { return ''; } else { return substr( $String, $Start, $Length ); } } ?>

« previous php.notes (#107270) next »