【[视频教程]LAMP兄弟连视PHP函数-preg_match】教程文章相关的互联网学习教程文章

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 – 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修饰符,则模式中的字母将匹配大写和小写字母.

PHP preg_match与正则表达式【代码】

参见英文答案 > Validate date format in php 7个 function validateDate( $date ) { echo $date;//2012-08-24 20:30:00if(preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([1-2]{1})([0-9]{1}):([0-5]{1})([0-9]{1}):([0-5]{1})([0-9]{1})$/', $date) >= 1){return true;}else{return false;} }这总是返回false.我使用了一个唯一的工具来构建正则表达式,它在那里工作得很好.当我将“/”添加...

php – 正则表达式(preg_match)【代码】

这是不工作的代码:<?php $matchWith = " http://videosite.com/ID123 "; preg_match_all('/\S\/videosite\.com\/(\w+)\S/i', $matchWith, $matches); foreach($matches[1] as $value) { print '<a href="http://videosite.com/'.$value.'">Hyperlink</a>'; } ?>我想要的是,如果它之前或之后有空格,它不应该显示链接.所以现在它什么都不显示.但它仍然显示链接.解决方法:这也可以匹配ID12,因为3不是空格,而http:/不是...

php – preg_match多个IP?【代码】

我正在使用preg_match来匹配引用的URL AND和IP块.如何告诉我的代码查找引用,如果匹配则检查多个IP块?即:70.x.x.x或96.x.x.x. 这是我到目前为止的代码(适用于一个IP块“70.x.x.x”)<?php $referrer = $_SERVER['HTTP_REFERER']; $visitor = $_SERVER['REMOTE_ADDR']; if ((preg_match("/referrer-domain.com/",$referrer)) && (!preg_match("/70./",$visitor))){ echo "<meta http-equiv='refresh' content='0;url=http://www.new...

php – preg_match字符串中的所有单词【代码】

寻找可能检测$string是否匹配$array中的所有单词.预先未知的单词顺序(用户输入的文本).array('test','shmest','zest','fest','etcest' );我承诺我可以:$is_match = true; foreach ($array as $word) {if (!strpos($string, $word) === false) {$is_match = false;break;} }(可以|应该)我通过preg_match [_all]做出如上所述的事情吗? EDIT1 优先级是内存和快速工作. 测试了2个unswers并拥有上面的https://eval.in/144266所以我的速...

preg_match,数字为PHP【代码】

我用这个时:preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', 0.0001);返回值为1,当我使用它时:preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', 0.00001);返回值为0. 有人可以说我为什么好吗?谢谢 !解决方法:由于小浮点数通常使用指数表示法显示,因此0.00001将转换为1.0E-5,这与正则表达式不匹配.如果您只是这样做,您可以看到:echo 0.00001;正则表达式应该与字符串一起使用,而不是数字.preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?...

php – 使用preg_match检查字母数字点破折号和下划线的正则表达式是什么?【代码】

我正在检查用户输入的用户名 我正在尝试使用preg_match()在PHP中验证用户名,但我似乎无法按照我想要的方式运行它.我需要preg_match()来: >只接受字母,数字和. – _ 即只有字母数字点划线和下划线,我试过htaccess的正则表达式,就像这样([A-Za-z0-9.-_]+)喜欢这种方式,但它似乎没有工作,它给简单的alpha用户名假.$text = 'username';if (preg_match('/^[A-Za-z0-9.-_]$/' , $text)) {echo 'true'; } else {echo 'false'; }我怎样...

php – 来自`preg_match`的p代表什么?

参见英文答案 > What does preg stand for in PHP’s functions? 1个在ruby中,有一个名为gsub的函数,其中g代表全局,sub代表替换. 什么来自preg_match? 我认为reg是常规的,匹配真的很匹配.那是对的吗?解决方法:它代表“Perl REGular表达式”.

php – preg_match使用或不使用第一个大写字母查找正则表达式【代码】

在我的项目中,我需要找到一个特殊的正则表达式,如果第一个字母是大写或小写.以下是示例字符串:user = username User = username现在,我尝试了这个正则表达式:'/[^\n]user[^\n]*/'但如果第一个字母是大写字母,这个表达式找不到任何东西,所以我的问题是: 在两种情况下,找到包含“user”的行的正确正则表达式是什么?解决方法:您可以使用以下正则表达式:$re = "/^user.*$/mi"; 见demo i选项表示“忽略大小写”,m表示“多行”,强制...

Phpmailer弃用eregi到preg_match转换?【代码】

我做了研究,转换为不使用已弃用的代码看起来很直接,但我对正则表达式的经验是有限的,我不太清楚这个问题的解决方案是什么. 这是原始行:if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {这在5.3.0中已弃用 所以我替换为:if(preg_match('^(.+):([0-9]+)$/i', $hosts[$index], $hostinfo)) {现在我明白了:No ending delimiter ‘^’ found in…我正在阅读的所有内容都表明我需要一个^和一个/来分隔我的功能.有任何想法吗...