note 52843 added to function.strpos

From: Date: Sat, 14 May 2005 11:52:32 +0000
Subject: note 52843 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-89413@lists.php.net to get a copy of this message
I often need to find out the nearest position of whatever character contained in an array. Because I couldn't find an implemented PHP function, I wrote the following: <?php function findnextocc($hay, $needle=array('"','"'), $startpos=0) { // Finds nearest position of whatever char insite the needle array // (C) ZANA digital | http://www.unbeirrbareinenwegverfolgen.de/ $nil=strlen($hay); $min=$nil; $mkey=''; foreach ($needle as $key => $value) { $i=strpos($hay,$value,$startpos); if (($i!==false) and ($i<$min)) { $min=$i; $mkey=$value; } } if ($min!=$nil) return array($min,$mkey); return false; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52843 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52843&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52843&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52843&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52843&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52843&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52843&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89413) next »