Php: how to find a substring in a specified string _ PHP Tutorial

Source: Internet
Author: User
Php implements the method of searching for substrings in a specified string. Php: how to find a substring in a specified string this article mainly introduces the php method to find a substring in a specified string, involving strpos () in php () function search string technology php implements the method of searching for substrings in a specified string

This article mainly introduces php's method to find sub-strings in specified strings. it involves the strpos () function in php to find strings. it has some reference value. For more information, see

This example describes how to find a substring in a specified string in php. Share it with you for your reference. The specific analysis is as follows:

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

?

1

2

3

4

5

6

7

8

9

10

11

$ Haystack1 = "2349534134345w3mentor16504381640415488129 ";

$ Haystack2 = "w3mentor234953413434516504381640410488129 ";

$ Haystack3 = "center234953413434516504381640109488129fyi ";

$ 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 ");

?>

Output result:

?

1

2

3

Pos1 = (13); type is integer

Pos2 = (0); type is integer

Pos3 = (); type is boolean

Pos3 returns the bool value, that is, the substring is not found.

I hope this article will help you with php programming.

This article describes how to use php to find sub-strings in specified strings. it involves the strpos () function in php to find strings...

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.