PHP substr_replace() เปลี่ยนข้อความภายในส่วนของข้อความที้ได้ทำการตัดตำแหน่งที่ต้องการ
Syntax
<?php
substr_replace($string,$replace,$int-start,$int-end)
?>
Sample
<?php
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var<hr />\n";
/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . "<br />\n";
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />\n";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . "<br />\n";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . "<br />\n";
echo substr_replace($var, 'bob', -7, -1) . "<br />\n";
/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . "<br />\n";
?>

Screenshot
Reference : https://www.thaicreate.com/php-manual/function.substr-replace.html

|