What is the usage of php regex?

藏色散人
Release: 2023-03-13 14:02:02
Original
2209 people have browsed it

php正则的用法:1、创建一个PHP示例文件;2、定义一个数组;3、通过正则表达式“preg_grep("/^(\d+)?\.\d+$/",$array);”进行替换即可。

What is the usage of php regex?

本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑

php正则的使用

函数 描述
preg_filter 执行一个正则表达式搜索和替换
preg_grep 返回匹配模式的数组条目
preg_last_error 返回最后一个PCRE正则执行产生的错误代码
preg_match_all 执行一个全局正则表达式匹配
preg_match 执行一个正则表达式匹配
preg_quote 转义正则表达式字符
preg_replace_callback_array 执行一个正则表达式搜索并且使用一个回调进行替换
preg_replace_callback 执行一个正则表达式搜索并且使用一个回调进行替换
preg_replace 执行一个正则表达式的搜索和替换
preg_split 通过一个正则表达式分隔字符串

preg_filter

preg_grep

Copy after login

preg_mactch_all

PHP 
Title: Programming Language"; preg_match_all ("/(.*)<\/b>/U", $userinfo, $pat_array); print_r($pat_array[0]); ?>
Copy after login
bold textclick me";
 
preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/", $html, $matches, PREG_SET_ORDER);
 
foreach ($matches as $val) {
    echo "matched: " . $val[0] . "\n";
    echo "part 1: " . $val[1] . "\n";
    echo "part 2: " . $val[2] . "\n";
    echo "part 3: " . $val[3] . "\n";
    echo "part 4: " . $val[4] . "\n\n";
}
?>
Copy after login

 推荐学习:《PHP视频教程

The above is the detailed content of What is the usage of php regex?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!