How PHP finds substrings in a specified string

Source: Internet
Author: User
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. 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.

<?php$haystack1 = "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");p rint (" POS1 = ($pos 1); Type is ". GetType ($pos 1). "\ n");p rint ("Pos2 = ($pos 2); Type is ". GetType ($pos 2). "\ n");p rint ("POS3 = ($pos 3); Type is ". GetType ($pos 3). "\ n");? >

Output Result:

POS1 = (13); Type is Integerpos2 = (0); Type is INTEGERPOS3 = (); Type is Boolean

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

Summary : The above is the entire content of this article, I hope to be able to help you learn.

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.