PHP chunk_split()ฟังก์ชัน
ตัวอย่าง
แยกสตริงหลังอักขระแต่ละตัวและเพิ่ม "." หลังจากการแยกแต่ละครั้ง:
<?php
$str = "Hello world!";
echo chunk_split($str,1,".");
?>
ความหมายและการใช้งาน
ฟังก์ชัน chunk_split() แบ่งสตริงออกเป็นชุดย่อยๆ
หมายเหตุ:ฟังก์ชันนี้จะไม่เปลี่ยนแปลงสตริงเดิม
ไวยากรณ์
chunk_split(string,length,end)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
string | Required. Specifies the string to split |
length | Optional. A number that defines the length of the chunks. Default is 76 |
end | Optional. A string that defines what to place at the end of each chunk. Default is \r\n |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ส่งกลับสตริงแยก |
---|---|
รุ่น PHP: | 4+ |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
แยกสตริงหลังอักขระตัวที่หกและเพิ่ม "..." หลังจากแยกแต่ละรายการ:
<?php
$str = "Hello world!";
echo chunk_split($str,6,"...");
?>
❮ การอ้างอิงสตริง PHP