Home > Backend Development > PHP Tutorial > How to use php strchr function

How to use php strchr function

藏色散人
Release: 2023-04-05 06:24:01
Original
4920 people have browsed it

PHP strchr function is used to find the first occurrence of a string. Its syntax is [strchr(string,search,before_search)]. The parameter string is required and specifies the string to be searched.

How to use php strchr function

php strchr function usage:

php strchr() function syntax

Function: Searches for the first occurrence of a string within another string.

Syntax:

strchr(string,search,before_search);
Copy after login

Parameters:

string Required. Specifies the string to be searched for.

search Required. Specifies the string to search for. If the argument is a number, searches for characters that match the ASCII value for that number.

before_search Optional. The default value is a Boolean value of "false". If set to "true", it returns the portion of the string preceding the first occurrence of the search parameter.

Description:

This function is an alias of the strstr() function. This function is binary safe. This function is case-sensitive. To perform a case-insensitive search, use the stristr() function.

php strchr() function usage example 1:

<?php
echo strchr("Hello php.cn!","php");
?>
Copy after login

Output:

php.cn
Copy after login

php strchr() function usage example 2:

<?php
echo strchr("i study php in php.cn!","study");
?>
Copy after login

Output:

study php in php.cn!
Copy after login

This article is an introduction to the PHP strchr function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php strchr function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template