note 63924 added to function.substr
| From: | andy at arakka dot co dot th | Date: | Tue, 04 Apr 2006 01:32:07 +0000 |
| Subject: | note 63924 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107257@lists.php.net to get a copy of this message | ||
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 );
}
}
?>
----
Server IP: 203.121.145.116
Probable Submitter: 58.147.86.83
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/note/edit/63924
Del: integrated -- http://master.php.net/note/delete/63924/integrated
Del: useless -- http://master.php.net/note/delete/63924/useless
Del: bad code -- http://master.php.net/note/delete/63924/bad+code
Del: spam -- http://master.php.net/note/delete/63924/spam
Del: non-english -- http://master.php.net/note/delete/63924/non-english
Del: in docs -- http://master.php.net/note/delete/63924/in+docs
Del: other reasons-- http://master.php.net/note/delete/63924
Reject -- http://master.php.net/note/reject/63924
Search -- http://master.php.net/manage/user-notes.php