note 38220 added to function.substr
| From: | thivierr at telus dot net | Date: | Fri, 12 Dec 2003 17:11:39 +0000 |
| Subject: | note 38220 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61868@lists.php.net to get a copy of this message | ||
Just to clarify the meaning of the statement "If string is less than start characters long,
FALSE will be returned. "
If string length is exactly equal to startpos, then false is returned (not a zero-length string).
Example:
substr("filename.txt",9,1)==='.txt'
but
substr("filename.",9,1)!=='.' (it equals false)
People often use this function to find a file extension (combined with strrpos). But, in the
special case where the dot (.) you have to have code to handle that case in a way you want.
People familiar with the "c" function of the same name, would have expected a zero-length
string.
Also, keep in mind that in the above example the use of *exact* comparison. You can only detect
the difference between a zero-length string and false, if you use exact comparison (===). The two
appear "equal" if you use approx match (==). As a result, this issue will not be
immediately apparent.
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38220
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38220&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38220&report=yes
Search -- http://master.php.net/manage/user-notes.php