INPUT
0801234567
ผลลัพธ์ที่ต้องการ
080123xxxx
ตัวอย่างโค้ด PHP
<?php
$tel_number = '0801234567';
$new_num = substr_replace($tel_number, 'xxxx', -4); //080123xxxx
echo '<h3>ผลลัพธ์</h3>';
echo $new_num;
?>
นอกจากใช้แทนที่เบอร์โทรศัพท์แล้ว ยังสามารถใช้แทนที่ข้อความอื่นๆ โดยกำหนดตำแหน่งต่างๆ ได้โดยสามารถอ่านรายละเอียดเพิ่มเติมได้ดังนี้
คำอธิบายฟังก์ชั่น
substr_replace
(PHP 4, PHP 5, PHP 7)
substr_replace — Replace text within a portion of a string
Description ¶
อ่านเพิ่มเติม
http://php.net/manual/en/function.substr-replace.php
stringdelimited by thestartand (optionally)lengthparameters with the string given inreplacement.