What is the usage of strstr function in php

王林
Release: 2023-03-11 09:36:02
Original
2246 people have browsed it

The usage of strstr function in php is to search whether a string exists in another string, such as [strstr("Hello world!",111);]. If present, the function returns the string and the remainder.

What is the usage of strstr function in php

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

strstr() function searches whether a string exists in another string. If so, returns the string and the remaining part, otherwise returns FALSE.

For example, search the string through the ASCII value of "o" and return the remaining part of the string

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>
Copy after login

Running result:

o world!
Copy after login

For example, we want to return " world" The string part before the first appearance

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>
Copy after login

Running results:

Hello
Copy after login

Related video tutorial sharing: php video tutorial

The above is the detailed content of What is the usage of strstr function in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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