note 38220 deleted from function.substr by nlopess
| From: | nlopess@php.net | Date: | Sat, 03 Jul 2004 12:06:07 +0000 |
| Subject: | note 38220 deleted from function.substr by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72411@lists.php.net to get a copy of this message | ||
Note Submitter: thivierr@telus.net
----
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.