note 121058 deleted from function.substr by cmb

From: Date: Sun, 27 Oct 2019 09:08:20 +0000
Subject: note 121058 deleted from function.substr by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212826@lists.php.net to get a copy of this message
Note Submitter: kleeh at bellsouth dot net ---- If I may, I'd like to add an example for a bit more clarification on the action of substr(). There's a note saying "If string is equal to start characters long, an empty string will be returned. Prior to this version, FALSE was returned in this case. ". That description puzzled me until I worked it out. So, if your string is "x" and you do 'substr("x",0, 1)' then you'll get "x" as expected. Same thing for substr("x",0,4)' or any other LENGTH parm. But if the START parm is equal to the LENGTH of the string, then you'll get an empty string (PHP 7) or FALSE (prior to PHP 7). An example of this would be 'substr("x", 1, 1)' , which would return either an empty string or FALSE. Because your "x", which has a LENGTH of '1', is in the 0th position, so 'starting' your substr request at position 1 results in the empty string (or FALSE) because there is nothing after your "x" in this example. Just trying to mitigate some head-scratching over the phrasing of the previous note.

« previous php.notes (#212826) next »