note 36290 deleted from function.strpos by nlopess

From: Date: Tue, 25 Jul 2006 11:22:17 +0000
Subject: note 36290 deleted from function.strpos by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-115150@lists.php.net to get a copy of this message
Note Submitter: peous at djingle dot com ---- Function to find the first occurence of any object of the array. <?php function findfirstof( $txt, $arr, $start ) { $pos = -1; foreach( $arr as $v ) { $p = strpos( $txt, $v, $start ); if ($p===FALSE) continue; if (($p<$pos)||($pos==-1)) $pos = $p; } return $pos; } ?> Ex: $str = "find, the first word..."; $firstW = findfirstof( $str, ",?.:!" ); //returns "find"

« previous php.notes (#115150) next »