note 36290 modified in function.strpos by aidan
| From: | aidan@php.net | Date: | Thu, 10 Jun 2004 06:59:28 +0000 |
| Subject: | note 36290 modified in function.strpos by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70815@lists.php.net to get a copy of this message | ||
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"
--was--
Function to find the first occurence of any object of the array.
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"
http://www.php.net/manual/en/function.strpos.php