PHP strchr() Function


The strchr() function is used to search for the first occurrence of a given string .It is alias of strstr() function.

Syntax
strchr(string,search,before_search)
Parameters
  • String - (Required) Specify the string to search.
  • search - (Required) Specify the string to search .if this parameter is a number then return ASCII value.
  • before_search - (optional) it is false because defalut value.if it is returns true part of the string before the first occurrence of the search parameter.
Example
<?php
    echo strchr("Hii Hello!","Hello");
?>

Output

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

Output

Hii

Prev Next