lol, to s tym dvojitym priradenim do $f je preklep :-D
Nahradzovanie uz nahradenych poloziek - teraz som v tom nasiel dva bugy:
1) premenna $pos je zakazdym nulovana - ta definicia $pos=0 mala ist este pred ten for...
2) vypocet pozicie $pos = [podtrzene]$found_i[/podtrzene]+$replace_len; je zly lebo found_i je index polozky, ktoru hladam v poli, a nie pozicia. mala tam byt $found_at.
...I'm very many sorry, netestoval som to, ale uz by to malo byt O.K. :-)
real_count -- skutocny pocet nahradenych:
$subject = limited_str_replace($find,$replacement,$subject,null, $pocet);
echo $pocet;
Takze este raz, dufam ze uz bez chyb:function limited_str_replace($find,$replacement,$subject,$max=null,&$real_count=0)
{
if (!is_array($find)) $find = Array($find);
if (!is_array($replacement)) $replacement = Array($replacement);
$real_count=0; $pos=0;
for($count=0;$count<$max || $max==null;$count++)
{
$found_at=null; $found_i=null;
foreach($find as $i => $f)
{
$p=strpos($subject,$f,$pos);
if ($p!==false && ($found_at===null || $p<$found_at))
{
$found_at = $p;
$found_i = $i;
}
}
if ($found_i!==null)
{
$found_len = strlen($f=$find[$found_i]);
$replace_len = strlen($r=$replacement[$found_i]);
$subject = substr_replace($subject, $r, $found_at,$found_len);
$pos = $found_at+$replace_len;
$real_count++;
} else
break;
}
return $subject;
}