Latest web development tutorials

PHP strchr () function

PHP String Reference PHP String Reference

Examples

Find "world" in the first occurrence, and returns the rest of the string "Hello world!":

<?php
echo strchr("Hello world!","world");
?>

Running instance »

Definition and Usage

strchr () function searches for a string in another string of the first occurrence.

This function is strstr () alias function.

Note: This function is binary safe.

Note: This function is case-sensitive.For case-insensitive search, please use stristr () function.


grammar

strchr( string,search,before_search );

参数 描述
string 必需。规定被搜索的字符串。
search 必需。规定所搜索的字符串。如果该参数是数字,则搜索匹配该数字对应的 ASCII 值的字符。
before_search 可选。一个默认值为 "false" 的布尔值。如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分。

technical details

return value: The rest of the returned string (from the matching point). If the search string is not found, it returns FALSE.
PHP version: 4+
Update log: In PHP 5.3, add the before_search parameters.


More examples

Example 1

Through the "o" in the ASCII value of the search string and returns the remainder of the string:

<?php
echo strchr("Hello world!",111);
?>

Running instance »

Example 2

Returns the "world" part of the string before the first occurrence of:

<?php
echo strchr("Hello world!","world",true);
?>

Running instance »


PHP String Reference PHP String Reference