วิธีการแทนที่ตัวเลข 4 ตัวท้ายของเบอร์โทรศัพท์
INPUT
ตัวอย่างโค้ด PHP
นอกจากใช้แทนที่เบอร์โทรศัพท์แล้ว ยังสามารถใช้แทนที่ข้อความอื่นๆ โดยกำหนดตำแหน่งต่างๆ ได้โดยสามารถอ่านรายละเอียดเพิ่มเติมได้ดังนี้
อ่านเพิ่มเติม
http://php.net/manual/en/function.substr-replace.php
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 ¶
substr_replace() replaces a copy of
string delimited by the start and (optionally) length parameters with the string given in replacement.อ่านเพิ่มเติม
http://php.net/manual/en/function.substr-replace.php
ความคิดเห็น
แสดงความคิดเห็น