PHP stristr()ฟังก์ชั่น
ตัวอย่าง
ค้นหาการเกิดขึ้นครั้งแรกของ "โลก" ใน "สวัสดีชาวโลก!" และส่งคืนสตริงที่เหลือ:
<?php
echo stristr("Hello world!","WORLD");
?>
ความหมายและการใช้งาน
ฟังก์ชัน stristr() ค้นหาการเกิดขึ้นครั้งแรกของสตริงภายในสตริงอื่น
หมายเหตุ:ฟังก์ชันนี้มีความปลอดภัยแบบไบนารี
หมายเหตุ:ฟังก์ชันนี้คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ สำหรับการค้นหาแบบคำนึงถึงขนาดตัวพิมพ์ ให้ใช้ฟังก์ชันstrstr()
ไวยากรณ์
stristr(string,search,before_search)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
string | Required. Specifies the string to search |
search | Required. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number |
before_search | Optional. A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter. |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ส่งคืนสตริงที่เหลือ (จากจุดที่ตรงกัน) หรือ FALSE หากไม่พบสตริงที่ต้องการค้นหา |
---|---|
รุ่น PHP: | 4+ |
บันทึกการเปลี่ยนแปลง: | พารามิเตอร์ before_searchถูกเพิ่มใน PHP 5.3 ฟังก์ชันนี้ทำให้ไบนารีปลอดภัยใน PHP 4.3 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ค้นหาสตริงสำหรับค่า ASCII ของ "o" และคืนค่าสตริงที่เหลือ:
<?php
echo stristr("Hello world!",111);
?>
ตัวอย่าง
ส่งกลับส่วนของสตริงก่อนการเกิดขึ้นครั้งแรกของ "โลก":
<?php
echo stristr("Hello world!","WORLD",true);
?>
❮ การอ้างอิงสตริง PHP