note 81678 deleted from function.substr by danbrown

From: Date: Fri, 28 Nov 2008 20:17:54 +0000
Subject: note 81678 deleted from function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147196@lists.php.net to get a copy of this message
Note Submitter: yorn at no dot spam at niroj.com ---- kriskra's charAt script has the nifty feature that when $pos == -1, it will give the last letter of the string. I am not sure (did not test), but I believe this code might be slightly faster: <?php /** * Function to get a single character from a string * * @param string $str String to get char from * @param integer $pos Get char from this position of $str. Should be zero or greater * @return mixed Integer -1 when $pos is out of range, otherwise the charater at position $pos. */ function charAt($str, $pos) { return ($pos < 0 || $pos >= strlen($str)) ? -1 : $str{$pos}; } ?> Please note that this version does NOT have this nifty feature. When $pos == -1, result will be -1.

« previous php.notes (#147196) next »