note 38552 added to function.substr

From: Date: Fri, 26 Dec 2003 22:03:26 +0000
Subject: note 38552 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-62525@lists.php.net to get a copy of this message
As per the post below, posted 12-dec-2003, The examples given are incorrect, >>If string length is exactly equal to startpos, then false is returned (not a zero-length >>string). Example: >>substr("filename.txt",9,1)==='.txt' substr ("filename.txt", 9, 1) === 'txt' the substr function is 0 based, not 1, thus as stated in the description the first character is 0, the second is 1. >>but >>substr("filename.",9,1)!=='.' (it equals false) substr("filename.",9,1) should equal false, as there is no 10th character is the given string -- as per the documentation. >>People familiar with the "c" function of the same name, would have expected a >>zero-length string. PHP strings are not implictly null-terminated, thus the length of the string ("filename.") is 9. and the max start position would be 8 (the ninth character). There is no terminating null character at position #9, and thus the difference between this and the "c" version. ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38552 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38552&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38552&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62525) next »