Home > Backend Development > PHP Tutorial > How to use regular expressions for string search in php_PHP tutorial

How to use regular expressions for string search in php_PHP tutorial

WBOY
Release: 2016-07-13 10:00:37
Original
890 people have browsed it

How to use regular expressions for string search in php

This article mainly introduces the method of using regular expressions for string search in php, and analyzes php regular expressions with examples The usage skills of the formula have certain reference value. Friends in need can refer to it

The example in this article describes how PHP uses regular expressions to search for strings. Share it with everyone for your reference. The specific implementation method is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

$string_to_search = "jb51.net";

$regex = "/tor/";

$num_matches = preg_match($regex, $string_to_search);

if ($num_matches > 0) {

echo "Found a match!";

} else {

echo "No match. Sorry.";

}

?>

1 2

3

4 5

67 8 9 10 11
$string_to_search = "jb51.net";
$regex = "/tor/";<🎜> <🎜>$num_matches = preg_match($regex, $string_to_search);<🎜> <🎜> <🎜> <🎜>if ($num_matches > 0) { echo "Found a match!"; } else { echo "No match. Sorry."; } ?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/973128.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/973128.htmlTechArticleHow to use regular expressions for string search in php. This article mainly introduces the use of regular expressions for character search in php. String search method, example analysis of the use of PHP regular expressions...
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