รูปแบบคำสั่ง str_replace(find,replace,string,count)
find = ข้อมูลที่ทำการคนหา
replace = ข้อมูลที่จะนำไปแทนที่
string = ประโยคหรือข้อความที่จะทำการแทนทีคำ
count = ตำแหน่งหรือจำนวนของข้อมูลที่จะแทนที่ (จะใส่หรือไม่ใส่ก็ได้)
Code ตัวอย่าง 1
<?php
$string = "Hello world";
echo "result : ".str_replace("world","jonh",$string);
?>
ผลลัพธ์ตัวอย่าง 1
result : Hello jonh
-----------------------------------
Code ตัวอย่าง 2
<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "<br>" . "Replacements: $i";
?>
Array ( [0] => blue [1] => pink [2] => green [3] => yellow )
Replacements: 1
ไม่มีความคิดเห็น :
แสดงความคิดเห็น