ຫົວຂໍ້ PHP strchr()
ຕົວຢ່າງ
ຊອກຫາ "world" ໃນ "Hello world!" ເພື່ອການຄົ້ນຫາຄັ້ງທໍາອິດ ແລະ ກັບຄືນຕາມຄຳກ່າວນີ້:
<?php echo strchr("Hello world!","world"); ?>
Definition and usage
The strchr() function searches for the first occurrence of a string in another string.
This function is an alias of the strstr() function.
Note:This function is binary safe.
Note:This function is case sensitive. For a case-insensitive search, use stristr() Function.
Syntax
strchr(string,search,before_search);
Parameter | Description |
---|---|
string | Required. Specifies the string to be searched in. |
search |
Required. Specifies the string to be searched. If the parameter is a number, it will search for the character corresponding to the ASCII value of the number. |
before_search |
Optional. The default value is "false" boolean. If set to "true", it will return search The string part before the first occurrence of the parameter. |
Technical details
Return value: | ກັບຄືນຄຳທີ່ພາຍຫຼັງຈາກການພິມຄຳຊອກ (from the match point). If the search string is not found, it returns FALSE. |
PHP Version: | 4+ |
ບັນທຶກການປັບປຸງ: | ໃນ PHP 5.3, ໄດ້ສະເໜີມາ: before_search ຄວາມມູນປະກອບ |
ຕົວຢ່າງອື່ນ
ຕົວຢ່າງ 1
ການຊອກຫາຄຳໃນ ASCII ຄວາມ "o" ແລະກັບຄືນຄຳທີ່ພາຍຫຼັງ:
<?php echo strchr("Hello world!",111); ?>
ຕົວຢ່າງ 2
ການກັບຄືນ "world" ຄັ້ງທຳອິດຂອງຄຳໃນ:
<?php echo strchr("Hello world!","world",true); ?>