PHP implements a method for finding substrings in a specified string _php tutorial

Source: Internet
Author: User

PHP implements a method to find substrings in a specified string


This article mainly introduces the PHP implementation of the specified string to find a substring of the method, involving PHP strpos () function to find the string of skills, with a certain reference value, the need for friends can refer to the following

The example in this article describes the way that PHP implements finding substrings in a specified string. Share to 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 attempt to find the location where the substring first appears in the source string. If found, it returns a non-negative integer indicating where the substring appears. Otherwise it returns a Boolean value of false.

?

1

2

3

4

5

6

7

8

9

10

11

$haystack 1 = "2349534134345w3mentor16504381640386488129";

$haystack 2 = "w3mentor234953413434516504381640386488129";

$haystack 3 = "CENTER234953413434516504381640386488129FYI";

$pos 1 = strpos ($haystack 1, "W3mentor");

$pos 2 = Strpos ($haystack 2, "W3mentor");

$pos 3 = Strpos ($haystack 3, "W3mentor");

Print ("POS1 = ($pos 1); Type is ". GetType ($pos 1). "\ n");

Print ("Pos2 = ($pos 2); Type is ". GetType ($pos 2). "\ n");

Print ("POS3 = ($pos 3); Type is ". GetType ($pos 3). "\ n");

?>

Output Result:

?

1

2

3

POS1 = (13); Type is integer

Pos2 = (0); Type is integer

POS3 = (); Type is Boolean

POS3 returns a bool value, i.e. no substring found

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/969354.html www.bkjia.com true http://www.bkjia.com/PHPjc/969354.html techarticle PHP implements a method to find substrings in a specified string this article mainly introduces the method of finding substrings in the specified string in PHP, involving the Strpos () function in PHP to find the string ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.