ไม่มีครับ ฟังค์ชั่นแบบนั้น (หรือมีแต่ผมไม่รู้ แต่ไล่แล้วมันหาไ่ม่เจอ)
เลยเขียนให้ตัวหนึ่งละกัน (กำลังอู้งาน
)
ตัวอย่างคือ ข้ามคำแรก แล้วแทนที่ 2 คำนะครับ
function replace_skip($find, $replace, $string, $skip=false, $limit=false) {
##This function by EThaiZone
//Skip string
$c = ($skip===false ? 1 : $skip);
for($i=0; $i < $c; $i++){
$pos = strpos($string, $find, $pos+1);
if($pos !== false) if($skip===false) $c++;
}
$len = strlen($replace);
//Replace string
$c = ($limit===false ? 1 : $limit);
for($i=0; $i < $c; $i++){
$pos = strpos($string, $find, $pos+1);
if($pos !== false) {
$string = substr_replace($string, $replace, $pos, $len);
if($limit===false) $c++;
}
}
return $string;
}
$string = "000 aaa 111 aaa 222 aaa 333 aaa 444";
echo replace_skip("aaa", "---", $string, 1, 2);
ถ้าหัดเขียนฟังค์ชั่นใช้เองไว้่ จะสะดวกมากครับ