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

WBOY
Release: 2016-07-13 10:02:57
Original
920 people have browsed it

PHP’s method of finding substrings in specified strings

This article mainly introduces the method of PHP’s method of finding substrings in specified strings, involving strpos in PHP The technique of searching strings using () function has certain reference value. Friends who need it can refer to it

The example in this article describes the method of finding substrings in a specified string in PHP. 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.

?

1

2

3

4

5

6

7

8

9

10

11

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

?>

1 2

3

4

5

6

1

2

3

pos1 = (13); type is integer

pos2 = (0); type is integer

pos3 = (); type is boolean

7 8

9

10 11

$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");<🎜> <🎜>?>
Output result: ?
1 2 3 pos1 = (13); type is integer pos2 = (0); type is integer pos3 = (); type is boolean
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. http://www.bkjia.com/PHPjc/969354.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969354.htmlTechArticleHow to find substrings in a specified string in php. This article mainly introduces how to find substrings in a specified string in php. The method of finding substrings involves the strpos() function in php to find strings...
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