|
Posted by Rik on 08/11/06 23:48
DOH,
some checking and bad markup left in, should be:
function some_function($needle,$string,$all=false,$case=true){
$chars = str_split($needle,1);
$del = array_fill(0,count($chars),'/');
$pattern = '/'.implode('\s*?',array_map('preg_quote',$chars,$del)).'/s';
if($case) $pattern .= 'i';
if($all){
preg_match_all($pattern,$string,$matches,PREG_SET_ORDER+PREG_OFFSET_CAPTURE)
;
if(empty($matches)) return false;
$return = array();
foreach($matches as $key => $match){
$return[$key]['start'] = $match[0][1];
$return[$key]['end'] = $match[0][1] + strlen($match[0][0]);
}
return $return;
} else {
preg_match($pattern,$string,$matches,PREG_OFFSET_CAPTURE);
if(empty($matches)) return false;
return array('start' => $matches[0][1],'end' => $matches[0][1] +
strlen($matches[0][0]));
}
}
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|