English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and example of PHP strchr() function

    PHP String manual of string functions

    The strchr() function is used to find the first occurrence of a string in a string.

Syntax

strchr(string,search,before_search);

Definition and usage

It is used to search for the first occurrence of a string in another string

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

Return value

It returns the remaining string

Parameter

Serial numberParameter and description
1

string

Required. Specify the string to be searched.

2

search

Required. Specify the string to be searched. If this parameter is a number, it will search for the character corresponding to the ASCII value of the number.

3

before_search

Optional. A boolean value with a default value of "false". If set to "true", it will return the part of the string before the first occurrence of the search parameter.

Online example

Try the following example to find the first occurrence of "PHP" in "Hello PHP!":

<?php
   //Find the first occurrence of "PHP" in "Hello PHP!" and return the rest of the string found:
   echo strchr("Hello PHP!","PHP");
?>
Test and see‹/›

Output result

PHP!

PHP String manual of string functions