PHP strchr()ฟังก์ชัน
ตัวอย่าง
ค้นหาการเกิด "โลก" ครั้งแรกใน "สวัสดีชาวโลก!" และส่งคืนสตริงที่เหลือ:
<?php
echo strchr("Hello world!","world");
?>
ความหมายและการใช้งาน
ฟังก์ชัน strchr() ค้นหาการเกิดขึ้นครั้งแรกของสตริงภายในสตริงอื่น
ฟังก์ชันนี้เป็นนามแฝงของฟังก์ชันstrstr()
หมายเหตุ:ฟังก์ชันนี้มีความปลอดภัยแบบไบนารี
หมายเหตุ:ฟังก์ชันนี้คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ สำหรับการค้นหาที่ไม่คำนึงถึงขนาดตัวพิมพ์ ให้ใช้ฟังก์ชันstristr()
ไวยากรณ์
strchr(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 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ค้นหาสตริงสำหรับค่า ASCII ของ "o" และส่งคืนสตริงที่เหลือ:
<?php
echo strchr("Hello world!",111);
?>
ตัวอย่าง
ส่งกลับส่วนของสตริงก่อนการเกิดขึ้นครั้งแรกของ "โลก":
<?php
echo strchr("Hello world!","world",true);
?>