HOW DO I TWEAK THAT FUNCTION so instad of replace the only first match, it will replace FROM the first match? function str_replace_count($search,$replace,$subject,$times) { $subject_original=$subject; $len=strlen($search); $pos=0; for ($i=1;$i<=$times;$i++) { $pos=strpos($subject,$search,$pos); if($pos!==false) { $subject=substr($subject_original,0,$pos); $subject.=$replace; $subject.=substr($subject_original,$pos+$len); $subject_original=$subject; } else { break; } } $w="abracadabra"; print str_replace_count("abra","----",$w,2); return($subject); }