note 76861 added to function.strripos

From: Date: Thu, 02 Aug 2007 20:39:27 +0000
Subject: note 76861 added to function.strripos
Groups: php.notes 
Request: Send a blank email to php-notes+get-129132@lists.php.net to get a copy of this message
Actually, the above, "Simple way to implement this function in PHP 4" by Yanik Lupien, should be: <?php if (function_exists('strripos') == false) { function strripos($haystack, $needle) { return strlen($haystack) - strpos(strrev($haystack), strrev($needle)); } } ?> Note the reversal (<?php strrev($needle)?>) of the search string. This was left out in Yanik's example, and without it, you'll simply get the length of the haystack, as the forward string will not likely be found in the reversed haystack. Thus; if we reverse the haystack, any instance of the search string ($needle) therein will also be reversed, so we must reverse it to look for it. :) ---- Server IP: 208.69.120.35 Probable Submitter: 69.145.86.254 ---- Manual Page -- http://www.php.net/manual/en/function.strripos.php Edit -- https://master.php.net/note/edit/76861 Del: integrated -- https://master.php.net/note/delete/76861/integrated Del: useless -- https://master.php.net/note/delete/76861/useless Del: bad code -- https://master.php.net/note/delete/76861/bad+code Del: spam -- https://master.php.net/note/delete/76861/spam Del: non-english -- https://master.php.net/note/delete/76861/non-english Del: in docs -- https://master.php.net/note/delete/76861/in+docs Del: other reasons-- https://master.php.net/note/delete/76861 Reject -- https://master.php.net/note/reject/76861 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129132) next »