ฟังก์ชัน str_ireplace() ใช้เพื่อแทนที่อักขระด้วยอักขระอื่นๆ
หมายเหตุ − ฟังก์ชันไม่คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่
ไวยากรณ์
str_ireplace(find,replace,str,count)
พารามิเตอร์
-
ค้นหา − ค่าที่จะค้นหา
-
เปลี่ยน − ค่าที่จะแทนที่ค่าใน find
-
str − สตริงที่จะค้นหา
-
นับ - จำนวนการเปลี่ยน
คืนสินค้า
ฟังก์ชัน str_ireplace() จะคืนค่าสตริงหรืออาร์เรย์ด้วยค่าที่ถูกแทนที่
ต่อไปนี้เป็นตัวอย่าง −
ตัวอย่าง
<?php
$str = "I am Amit";
$res = str_ireplace("Amit", "David", $str);
echo $res;
?> ต่อไปนี้เป็นผลลัพธ์ -
ผลลัพธ์
I am David
เรามาดูตัวอย่างกัน −
ตัวอย่าง
<?php
$myArr = array("one","two","three");
print_r(str_ireplace("three","four",$myArr,$c));
echo "<br>" . "Number of Replacements = $c";
?> ต่อไปนี้เป็นผลลัพธ์ -
ผลลัพธ์
Array ( [0] => one [1] => two [2] => four ) Number of Replacements = 1