PHP implements the method of finding substrings in a specified string, searching in a string_PHP tutorial

WBOY
Release: 2016-07-13 10:02:49
Original
955 people have browsed it

php implements the method of finding substrings in a specified string. Searching in a string

The example in this article describes the method of php implementing the method of finding substrings in a specified string. Share it with everyone for your reference. The specific analysis is as follows:

The strpos() function can be used to find substrings in php. The strpos() function will try to find the first occurrence of a substring in the source string. If found, it returns a non-negative integer indicating the position of the substring. Otherwise it returns a boolean false.

<&#63;php
$haystack1 = "2349534134345w3mentor16504381640386488129";
$haystack2 = "w3mentor234953413434516504381640386488129";
$haystack3 = "center234953413434516504381640386488129fyi";
$pos1 = strpos($haystack1, "w3mentor");
$pos2 = strpos($haystack2, "w3mentor");
$pos3 = strpos($haystack3, "w3mentor");
print("pos1 = ($pos1); type is " . gettype($pos1) . "\n");
print("pos2 = ($pos2); type is " . gettype($pos2) . "\n");
print("pos3 = ($pos3); type is " . gettype($pos3) . "\n");
&#63;>
Copy after login

Output result:

pos1 = (13); type is integer
pos2 = (0); type is integer
pos3 = (); type is boolean
Copy after login

pos3 returns a bool value, that is, the substring is not found

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969500.htmlTechArticlephp implements the method of finding substrings in a specified string. Searching in a string The example of this article tells about the implementation of specifying in php Method to find substrings in a string. Share it with everyone for your reference...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!