note 85941 added to function.strripos

From: Date: Thu, 25 Sep 2008 16:31:19 +0000
Subject: note 85941 added to function.strripos
Groups: php.notes 
Request: Send a blank email to php-notes+get-144706@lists.php.net to get a copy of this message
Suppose you just need a stripos function working backwards expecting that strripos does this job, you better use the following code of a custom function named strbipos: <?php function strbipos($haystack="", $needle="", $offset=0) { // Search backwards in $haystack for $needle starting from $offset and return the position found or false $len = strlen($haystack); $pos = stripos(strrev($haystack), strrev($needle), $len - $offset - 1); return ( ($pos === false) ? false : $len - strlen($needle) - $pos ); } // Test $body = "01234Xy7890XYz456xy90"; $str = "xY"; $len = strlen($body); echo "TEST POSITIVE offset VALUES IN strbipos<br>"; for ($i = 0; $i < $len; $i++) { echo "Search in [$body] for [$str] starting from offset [$i]: [" . strbipos($body, $str, $i) . "]<br>"; } ?> Note that this function does exactly what it says and its results are different comparing to PHP 5 strripos function. ---- Server IP: 147.52.159.12 Probable Submitter: 87.203.123.99 ---- Manual Page -- http://www.php.net/manual/en/function.strripos.php Edit -- https://master.php.net/note/edit/85941 Del: integrated -- https://master.php.net/note/delete/85941/integrated Del: useless -- https://master.php.net/note/delete/85941/useless Del: bad code -- https://master.php.net/note/delete/85941/bad+code Del: spam -- https://master.php.net/note/delete/85941/spam Del: non-english -- https://master.php.net/note/delete/85941/non-english Del: in docs -- https://master.php.net/note/delete/85941/in+docs Del: other reasons-- https://master.php.net/note/delete/85941 Reject -- https://master.php.net/note/reject/85941 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144706) next »