This article mainly introduces the PHP regular expression matching, replacement and segmentation functions, briefly analyzes the PHP regular expression matching, replacement and segmentation related functions, and demonstrates the related operation skills of PHP regular expression matching in the form of examples. Friends who need it can For reference,
is as follows:
The functions of regular expressions in PHP mainly include: segmentation, matching, search and replacement.
Matching function
preg_match_all All matching functions
##
preg_match_all (string pattern,string subject,array matches[, int flags]);
Replacement function
preg_replace Regular replacement function
preg_replace(mixed pattern,mixed replacement,mixed subject[, int limit]);
② The replacement content can be solved by using the modifier e to solve the replacement execution content.
Split function
preg_split Regular cutting
preg_split(string pattern,string subject[, int limit[, int flags]]);
Example demonstration
Matching functionThe following is the reference content:<?php $str="标题:{title}内容:{content}"; $mode="/{(.*)}/U"; preg_match_all($mode,$str,$arr); print_r($arr); ?>
Array ( [0] => Array ( [0] => {title} [1] => {content} ) [1] => Array ( [0] => title [1] => content ) )
The most commonly used regular expressions in PHP
RegularExpressionDetailed explanation of statement comment steps
RegularUse of \B and \b in expression Detailed steps
The above is the detailed content of Example analysis of PHP regular expression matching, replacement and segmentation functions. For more information, please follow other related articles on the PHP Chinese website!