note 51578 added to function.strripos

From: Date: Mon, 04 Apr 2005 21:23:45 +0000
Subject: note 51578 added to function.strripos
Groups: php.notes 
Request: Send a blank email to php-notes+get-87450@lists.php.net to get a copy of this message
Odd behavior when using strripos() from PEAR PHP_Compat on php4.3.2 (OS X): if the needle is not found in the haystack, it does not return false as specified. Rather it returns strlen($needle)*-1 <? include ('PHP_Compat-1.3.1/Compat/Function/strripos.php'); $h = "thequickbrownfox"; echo strripos($h, "quick")."<br>"; echo strripos($h, "blah")."<br>"; echo strripos($h, "foo")."<br>"; ?> OUTPUTS: 3 -4 -3 Luckily, the workaround is pretty easy: $pos = strripos($h, $n); $pos = $pos ? $pos : false; ---- Manual Page -- http://www.php.net/manual/en/function.strripos.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51578 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51578&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51578&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51578&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51578&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51578&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51578&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87450) next »