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

php – preg_match()期望参数为给定的长字符串【代码】

我正在检查信用卡字段,以确保它们各包含四位数字.function creditcard ($creditCard1,$creditCard2,$creditCard3,$creditCard4) {$regexp="/^[0-9]{4}$/";if (preg_match($regexp,$creditCard1,$creditCard2,$creditCard3,$creditCard4))//line 18{return TRUE;}else{echo'<script type="text/javascript">alert("Enter a valid credit card number.")</script>';return FALSE;} }$creditCard1=$_POST['creditCard1'];$creditCard2...

正则表达式问题php preg_match【代码】

试图匹配以下内容: rawurl = “http://www.domain.com/page/etc/” URL本身是可变的,可以包含所有种类! ? querystrings等等.是否有逃避功能使其正则表达式安全? 所以到目前为止我有这个$var is already defined..$url = "www.adomain.com/with/extras/"$url = str_replace(" \/ ","/",$url); // maybe more needed here. $pattern = "/rawurl\=\"http\:\/\/$url/"; preg_match($pattern, $var, $out);正确格式...

php – 为什么preg_match_all()多次创建相同的答案?【代码】

以下代码从推文中提取#hashtags并将它们放在变量$matches中.$tweet = "this has a #hashtag a #badhash-tag and a #goodhash_tag";preg_match_all("/(#\w+)/", $tweet, $matches);var_dump( $matches );有人可以向我解释为什么以下结果有2个相同的数组而不是1个?array(2) {[0]=>array(3) {[0]=>string(8) "#hashtag"[1]=>string(8) "#badhash"[2]=>string(13) "#goodhash_tag"}[1]=>array(3) {[0]=>string(8) "#hashtag"[1]=>str...

php – 我如何preg_match希伯来语中的单词【代码】

我需要一个在php中匹配希伯来语中的完整单词的函数. 请帮忙.解决方法:试试这个描述Unicode character properties的正则表达式:/\p{Hebrew}+/u

php – 为什么preg_match_all返回两个匹配项?【代码】

我试图识别一个字符串是否在使用preg_match_all的双引号之间有任何单词,但它是重复结果,并且第一个结果有两组双引号,其中被搜索的字符串只有一组. 这是我的代码:$str = 'Test start. "Test match this". Test end.'; $groups = array(); preg_match_all('/"([^"]+)"/', $str, $groups); var_dump($groups);var转储产生:array(2) {[0]=>array(1) {[0]=>string(17) ""Test match this""}[1]=>array(1) {[0]=>string(15) "Test matc...

php – preg_match用于评论的某些部分【代码】

我想找到评论的某些部分.以下是一些例子/** @todo name another-name taskID*//* @todo name another-name taskID */目前我使用以下正则表达式'/\*[[:space:]]*(?=@todo(.*))/i'这返回以下内容:* @todo name another-name taskID or * @todo name another-name taskID */我怎么能得到@todo和名字,但不是任何星号? 期望的输出@todo name another-name taskID @todo name another-name taskID解决方法:试试这个:$str=<<<STR /** @...

php – 匹配模式并使用preg_match_all排除子串【代码】

我需要找到START和END之间的所有字符串,包括匹配字符串中的PADDING子字符串.我发现的最好方法是$r="stuffSTARTthisPADDINGisENDstuffstuffSTARTwhatPADDINGIwantPADDINGtoPADDINGfindENDstuff" ; preg_match_all('/START(.*?)END/',str_replace('PADDING','',$r),$m); print(join($m[1])); > thisiswhatIwanttofind我想用尽可能最小的代码大小来做这个:只有preg_match_all和没有str_replace的更短,最终直接返回没有连接数组的字符...

php – 从preg_match_all()突出显示主题字符串中的匹配结果【代码】

我试图用preg_match_all()返回的$matches数组突出显示主题字符串.让我从一个例子开始:preg_match_all("/(.)/", "abc", $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);这将返回:Array ([0] => Array([0] => Array([0] => a[1] => 0)[1] => Array([0] => a[1] => 0))[1] => Array([0] => Array([0] => b[1] => 1)[1] => Array([0] => b[1] => 1))[2] => Array([0] => Array([0] => c[1] => 2)[1] => Array([0] => c[1] => 2)))...

php – preg_match_all html标记,但双引号或单引号中的标记除外【代码】

鉴于这个DOM$html=<<<'EOD' <div class='container clickable' data-param='{"footer":"<div>Bye</div>","info":"We win"}'><img src='a.jpg' /> </div> <a href='a.html'>The A</a> <span></span> <span data-span-param='{"detailTag":"<span class=\"link\">Anything here</span>"}'><a></a> </span> EOD; 我正在尝试使用此表达式preg_match_all html标记:$tags = array(); if(preg_match_all('~<\s*[\w]+[^>]*>|<\s*/\s*[\...

来自Array with Multine的PHP正则表达式preg_match与所有块都不匹配【代码】

想知道是否有人可以帮助我使用以下正则表达式,我无法匹配块多线CF. {Coordonnees Abonne}:在PHP的preg_match函数中使用时. 奇怪的是,当我在线进行正则表达式时,尽管该块在另一组regex101 example中,它似乎仍然有效 这是代码:source code<?php $response = array(1 => 'CF.{Temps}: 1',2 => 'CF.{Etat}: return',3 => 'CF.{Code}: 2',4 => 'CF.{Values}: plaque',5 => '',6 => 'CF.{Coordonnees}: LA PERSONNE',7 => ' ...

PHP – Preg_match最短匹配【代码】

我正试图从这个字符串中获取“内容”:$string = "start start content end";像preg_match这样:preg_match('/start(.*?)end/', $string, $matches); echo $match[1];但是,问题是$matches [1]返回开始内容不仅仅是内容,因为$string中有两个开头(也许更多) 如何只使用preg_match获取内容部分?解决方法:使用否定前瞻:$string = "start start content end"; preg_match('/start\h*((?:(?!start).)*)end/', $string, $matches); echo...

用于分隔字符串的PHP preg_match_all正则表达式【代码】

任何人都可以帮我完成我的正则表达式吗? 我的字符串格式如下:<FC012D>{p:19}Ja?<BF093C> Du m?chtest<BC>zur K?nigin?<BC><BF040027><BF07>{p:20}<F8012D>Hmm...<BF093C><BC>Du bist gekommen um den<BC>Titel Kriegerin<BC>zu erhalten?<BD><BC>Verstehe.<BF093C> Das ist ganz<BC>sch?n tapfer für so<BC>eine junge Dame.<BD><BC>Die K?nigin wird sicher<BC>auch sehr<BC>überrascht sein.<BD><BC>{t:19}Bitte sehr,<BC>geh ...

使用php preg_match_all&cURL从多个页面中抓取/下载图像【代码】

所以我试图从另一个网站抓取一些图像,问题是每个图像都在不同的页面上 IE:id / 1,id / 2,id / 3等等 到目前为止,我有下面的代码,可以从使用下面给出的单个URL获取图像:$returned_content = get_data('http://somedomain.com/id/1/');但需要让上面的一行成为一个数组(我猜)所以它将从第1页抓取图像,然后继续抓住第2页上的下一个图像,然后是第3页等等function get_data($url){$ch = curl_init();$timeout = 5;curl_setopt($ch,CURL...

php preg_match – >在变量中保存匹配的值?【代码】

我的$content变量存储了youtube视频链接.$youtubeurl = "/(\[TRACK=)((http|https)(\:\/\/)(www|it|co\.uk|ie|br|pl|jp|fr|es|nl|de)(\.youtube\.)(com|it|co\.uk|ie|br|pl|jp|fr|es|nl|de)([a-zA-Z0-9\-\.\/\?_=&;]*))(\])/si"; $video = preg_match($youtubeurl, $content , $found); print_r($video); // 1如何将匹配字符串的值存储在变量中?现在,如果我print_r($video)我刚刚打印1表示已找到它.但是我需要在变量中保存找到的字...

php – ereg()到preg_match()怎么样?【代码】

我有一些我正在使用的简单正则表达式. 这很简单:"user/" "user/[A-z0-9_-]"这些都适用于ereg,但不是preg. 如何转换呢? 谢谢解决方法:这很可能是因为你错过了delimiters.试试这个:"~user/~" "~user/[A-z0-9_-]~"