Home Backend Development PHP Problem How to use php stristr function?

How to use php stristr function?

May 30, 2019 pm 01:31 PM

php The stristr function is used to search for the first occurrence of a string in another string. Its syntax is stristr(string,search,before_search). The parameter string is required and specifies the string to be searched; search is required and specifies The string to search for.

How to use php stristr function?

#php How to use stristr function?

Definition and Usage

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

Note: This function is binary safe.

Note: This function is not case sensitive. For case-sensitive searches, use the strstr() function.

Syntax

stristr(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 parameter is a number, search for characters matching the ASCII value corresponding to the number.

before_search Optional. The default value is a Boolean value of "false".

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

Return value: Returns the remaining part of the string (from the matching point). Returns FALSE if the searched string is not found.

PHP version: 4

Change log:

In PHP 5.3, the before_search parameter is added.

In PHP 4.3, this function becomes binary safe.

Example 1

Search for a string with the ASCII value of "o" and return the remainder of the string:

<?php
echo stristr("Hello world!",111);
?>
Copy after login

Output:

o world!
Copy after login

Example 2

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

<?php
echo stristr("Hello world!","WORLD",true);
?>
Copy after login

Output:

Hello
Copy after login

Example 3

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

<?php
echo stristr("Hello world!","WORLD");
?>
Copy after login

Output:

world!
Copy after login

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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1254
24