【php-使用fnmatch()匹配多个文件扩展名】教程文章相关的互联网学习教程文章

php-preg_match字符串中的所有段落【代码】

以下字符串包含多个< p&gt ;;标签.我想匹配每个< p>的内容.带有模式,如果匹配,我想向该特定段落添加一个CSS类. 例如,在以下字符串中,仅第二段内容匹配,因此我只想向该段添加一个类.$string = '<p>para 1</p><p>?? ???? ?? ?????</p><p>para3</p>';使用以下代码,我可以匹配所有字符串,但是无法弄清楚如何找到特定的段落.$rtl_chars_pattern = '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u'; $return = preg_match($rtl_chars_pattern...

带preg_match的PHP开关语句【代码】

我在switch语句内创建preg_match()时遇到一些问题. 我想编写与/ oop / page / view / [some-number]匹配的preg_match. 现在它的工作方式是: 如果我在浏览器http://example.com/oop/page/view/1中运行,则会显示“ 404页面”.而当我运行某个地址(例如http://example.com/oop/page/view/test)或什至/ oop / test运行第二种情况时,还不知道如何.可以肯定的是我的正则表达式表达有问题.public function check(){$url = filter_input(IN...

php-如何使用preg_match检查整个文本【代码】

嗨,我对preg_match函数有问题.我想针对模式检查整个文本,如果整个文本与模式匹配,则返回true;对于不匹配或部分与模式匹配,返回false,但是我无法使用php preg_match函数来做到这一点.例如,我使用波纹管功能来检查输入是否为数字或否.if(preg_match("/[\d]/","99ab") return true; else return false;上面的代码返回true,但是我想返回false.我想检查的其他正则表达式是用户的名字和姓氏preg_match.电话格式的另一个正则表达式(000)0...

php – 如何在preg_match中允许utf-8字符集?

我使用preg_match()函数只允许特定的charachters接受.它允许所有的alphabates和数字,但同时我也想允许utf-8字符,例如“”,那么我怎么能从preg_match()函数允许这个字符.Plase建议我.提前致谢. 问候 至尊解决方法:尝试/ u pattern modifier让PCRE引擎知道你正在使用UTF-8模式:This modifier turns on additionalfunctionality of PCRE that isincompatible with Perl. Patternstrings are treated as UTF-8. Thismodifier is avail...

php – 如何使用preg_match提取数据?【代码】

我对preg_match的使用很新.在发布此问题之前,我们已经搜索了很多答案.发现了很多帖子来获取基于youtube ID等的数据.但没有根据我的需要.如果它的愚蠢问题,请原谅我. 我需要从preg_match的字符串中获取ID.字符串是格式[#1234] Subject如何从字符串中仅提取“1234”?解决方法:一个解决方案是:\[#(\d+)\]这匹配左方括号和井号[#,然后捕获一个或多个数字,然后关闭右方括号]. 您会像以下一样使用它:preg_match( '/\[#(\d+)\]/', '[#1...

从php中使用preg_match_all的html表中获取数据【代码】

我有一个像这样的html表:<table ... ><tbody ... ><tr ... > <td ...>string...</td><td ...>string...</td><td ...>string...</td><td ...>string...</td><td ...>string...</td></tr><tr ... > <td ...>string...</td><td ...>string...</td><td ...>string...</td><td ...></td><td ...>string...</td></tr>..............</tbody></table>这是一个数据表,我需要从中获取所有数据.该表将有许多行(< tr>< / tr>).每行将具有固定...

php – 警告:preg_match()[function.preg-match]:未知修饰符'(‘【代码】

参见英文答案 > Warning: preg_replace(): Unknown modifier ‘]’ 3个我有这个HTML标签:<div class="title">Copy me if you can</div>所以我想用preg_match来“只要你能复制我”我正在使用这种preg模式:$preg = "<div class=\"title\">(.+?)</div>";所以我写了这段代码$match = preg_match($preg,$content);浏览器输出:Warning: preg_match() [function.preg-match]: Unknown modifier '('...

php – 使用preg_match识别强密码【代码】

我曾想过使用preg_match()来检查是否正确输入了密码.我想要至少1个大写字母,至少1个小写字母,至少一个数字,以及至少一个特殊字符.这是我正在使用的:$pattern = "(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$";这个正则表达式在HTML的“模式”字段中运行良好.但我需要确保它也适用于旧浏览器. 我的PHP代码是这样的:if (!(preg_match($pattern, $loginpassword))) {echo "Password must include one upperc...

php – 如何只返回带有preg_match或preg_match_all的命名组?【代码】

例:$string = "This is some text written on 2010-07-18."; preg_match('|(?<date>\d\d\d\d-\d\d-\d\d)|i', $string, $arr_result); print_r($arr_result);返回:Array ([0] => 2010-07-18[date] => 2010-07-18[1] => 2010-07-18 )但我希望它是:Array ([date] => 2010-07-18 )在PHP的PDO对象中,有一个选项是通过删除这些重复的编号值来过滤数据库中的结果:PDO::FETCH_ASSOC.但是我还没有看到PHP中PCRE函数的类似修饰符.解决方法...

php正则表达式中preg_match_all函数的详解

php正则表达式中的函数我们之前为大家结果一个preg_match函数,相信大伙对此有所了解,那么php正则表达式中preg_match_all函数的具体使用是如何的呢?今天我们就带大家了解php正则表达式中preg_match_all函数的详解!了解正则表达式之前,须要掌握一些常用的正则表达式的基础知识,这些如果能记得最好记得,记不住须要用的时候能查到就行,就多个特殊字符,所以说正则表达式玩的就是特殊,具体大家可以查看更加细致的说明。 preg_m...

php – 如何使用preg_match_all()获取子组匹配的所有捕获?【代码】

参见英文答案 > Get repeated matches with preg_match_all() 6个更新/注意事项:I think what I’m probably looking for is to get the 07001 in PHP.参考文献:PCRE regular expressions using named pattern subroutines. (仔细读:) 我有一个包含可变数量的段(简化)的字符串:$subject = 'AA BB DD '; // could be 'AA BB DD CC EE ' as well我想现在匹配段并通过匹配数组返回它们:$patt...

php – Laravel preg_match():找不到结尾分隔符’/’【代码】

我正在使用Laravel 4.2.我试图使用Validator验证名称字段与正则表达式,这是我的规则如下:public static $rules_save = ['class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/'];但是,只要我调用规则验证错误,请参阅下面的内容:preg_match(): No ending delimiter '/' found解决方法:由于你的正则表达式中有一个管道,你必须使用一个数组:public static $rules_save = ['class_subjects' => ['required', 'regex:/[0-9]([...

php – 警告:preg_match()[function.preg-match]:未知修饰符’/'[复制]【代码】

参见英文答案 > Warning: preg_replace(): Unknown modifier ‘]’ 3个我正在尝试使用preg_match来返回页面源代码中包含在“”中的所有URL. 我正在使用的代码是preg_match('"http://(.+?)\"', $code, $matches);我收到以下错误:Warning: preg_match() [function.preg-match]: Unknown modifier '/' in .... on line 13解决方法: preg_match('~"http://(.*)"~iU', $code, $matches); 你的问题是...

php – preg_match(); – 未知修饰符”【代码】

参见英文答案 > Warning: preg_replace(): Unknown modifier ‘]’ 3个好吧,所以我正在研究解析RSS提要.我得到了我不需要的数据,我剩下的就是解析游戏标题了. 这是我目前的代码(忽略了邋,,它只是一个概念证明):<?php $url = 'http://raptr.com/conexion/rss';$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($c...

php – 如何使这个preg_match不区分大小写?【代码】

考虑:preg_match("#(.{100}$keywords.{100})#", strip_tags($description), $matches);我试图在每一侧只显示100个字符,中间有搜索字符串. 此代码实际上有效,但它区分大小写.如何使其不区分大小写?解决方法:只需在分隔符#后添加i修饰符:preg_match("#(.{100}$keywords.{100})#i", strip_tags($description), $matches);如果设置了i修饰符,则模式中的字母将匹配大写和小写字母.