note 95171 modified in function.strrpos by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Dec 2009 15:01:32 +0000 |
| Subject: | note 95171 modified in function.strrpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164047@lists.php.net to get a copy of this message | ||
I couldn't find a function that would search a string for a min position of one of the chr of
an array. so this is my small function. If I'm wrong - please - correct me.
<?php
$array = array("!", "@", ":", ".", "/");
function strarr($string, $array, $offset)
{
$min=strlen($string);
foreach ($array as $v)
{
$pos = strpos($string, $v, $offset);
if($pos!="")
{
if($min>$pos)
{
$min=$pos;
}
}
}
return $min;
}
?>
If it didn't find any of the chr from the array, it will return the length of the whole string.
You are free to change it to false.
--was--
I couldn't find a function that would search a string for a min position of one of the chr of
an array. so this is my small function. If I'm wrong - please - correct me.
$array = array("!", "@", ":", ".", "/");
function strarr($string, $array, $offset)
{
$min=strlen($string);
foreach ($array as $v)
{
$pos = strpos($string, $v, $offset);
if($pos!="")
{
if($min>$pos)
{
$min=$pos;
}
}
}
return $min;
}
If it didn't find any of the chr from the array, it will return the length of the whole string.
You are free to change it to false.
http://php.net/manual/en/function.strrpos.php