note 52843 deleted from function.strpos by nlopess

From: Date: Sat, 14 May 2005 16:56:56 +0000
Subject: note 52843 deleted from function.strpos by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-89434@lists.php.net to get a copy of this message
Note Submitter: www.unbeirrbareinenwegverfolgen.de ---- 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; } ?>

« previous php.notes (#89434) next »