توابع PHP strchr()

مثال

جستجو برای اولین بار "world" در "Hello world!" و بخشی از این رشته را بازگردانید:

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

Run Instance

Definition and Usage

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

This function is an alias of the strstr() function.

Note:This function is binary safe.

Note:This function is case-sensitive. If you need a case-insensitive search, please use stristr() Function.

Syntax

strchr(string,search,before_search);
Parameter Description
string Required. Specify the string to be searched in.
search

Required. Specify 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" for the boolean value.

If set to "true", it will return search The string part before the first occurrence of the parameter.

Technical Details

Return Value: Return the rest of the string (from the match point). If the searched string is not found, return FALSE.
PHP Version: 4+
Update Log: In PHP 5.3, a new feature has been added: before_search Parameters.

More Examples

Example 1

Search for the string by the ASCII value of "o" and return the rest of the string:

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

Run Instance

Example 2

Return the string part before the first occurrence of the searched string:

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

Run Instance