note 76447 added to function.strrpos

From: Date: Mon, 16 Jul 2007 14:47:14 +0000
Subject: note 76447 added to function.strrpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-128614@lists.php.net to get a copy of this message
The documentation for 'offset' is misleading. It says, "offset may be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string." This is confusing if you think of strrpos as starting at the end of the string and working backwards. A better way to think of offset is: - If offset is positive, then strrpos only operates on the part of the string from offset to the end. This will usually have the same results as not specifying an offset, unless the only occurences of needle are before offset (in which case specifying the offset won't find the needle). - If offset is negative, then strrpos only operates on that many characters at the end of the string. If the needle is farther away from the end of the string, it won't be found. If, for example, you want to find the last space in a string before the 50th character, you'll need to do something like this: strrpos($text, " ", -(strlen($text) - 50)); If instead you used strrpos($text, " ", 50), then you would find the last space between the 50th character and the end of the string, which may not have been what you were intending. ---- Server IP: 64.71.164.2 Probable Submitter: 72.242.194.162 ---- Manual Page -- http://www.php.net/manual/en/function.strrpos.php Edit -- https://master.php.net/note/edit/76447 Del: integrated -- https://master.php.net/note/delete/76447/integrated Del: useless -- https://master.php.net/note/delete/76447/useless Del: bad code -- https://master.php.net/note/delete/76447/bad+code Del: spam -- https://master.php.net/note/delete/76447/spam Del: non-english -- https://master.php.net/note/delete/76447/non-english Del: in docs -- https://master.php.net/note/delete/76447/in+docs Del: other reasons-- https://master.php.net/note/delete/76447 Reject -- https://master.php.net/note/reject/76447 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128614) next »