A brief analysis of the implementation of Perl regular expressions in PHP_PHP tutorial

WBOY
Release: 2016-07-15 13:26:31
Original
915 people have browsed it

Perl regular expressions are implemented in PHP. We need to use PCRE-related regular expression functions. So what are the specific functions? Here we introduce 4 to you, hoping to be helpful to you.

Introduction to functions used in the implementation of Perl regular expressions in PHP:

1. preg_match:

Function format :

<ol class="dp-c"><li class="alt"><span><span>int preg_match(string pattern, string subject, </span><span class="keyword">array</span><span> [matches]);  </span></span></li></ol>
Copy after login

This function will use pattern expression in string to match. If [regs] is given, the string will be recorded in [regs][0], [regs][1 ] represents the first string recorded using brackets "()", [regs][2] represents the second string recorded, and so on. preg will return "true" if a matching pattern is found in string, otherwise it will return "false".

2. preg_replace:

Function format:

<ol class="dp-c"><li class="alt"><span><span>mixed preg_replace(mixed pattern, mixed replacement, mixed subject);  </span></span></li></ol>
Copy after login

This function will replace all strings in string that match the expression pattern Replacement for the expression. If the replacement needs to contain some characters of the pattern, you can use "()" to record it. In the replacement, you just need to use "

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446582.htmlTechArticlePerl regular expressions are implemented in PHP. We need to use PCRE-related regular expression functions, so specifically What functions are there? Here we introduce 4 to you, hope they will be helpful to you...
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