1

我只想问这个符号是什么。*?在 php 中的意思。这是示例代码:

    function parse($html) {
    //echo "Find table(id=weekdays)..\n";
    $pattern = "/(<table.*?id=\"weekdays\".*)/ims";
    //$pattern = "/(<div.*?id=\"flexBox_flex_calendar_mainCal\".*)/ims";
    //echo $pattern."\n";
    $match = array();
    //$html = str_replace("\r", "", $html);
    //$html = str_replace("\n", "", $html);
    if (preg_match($pattern, $html, $match) > 0) {
        //print_r($match);
        //echo $match[1];
        //echo count($match);
        $this->parseTable($match[1]);
    } else {
        echo "Error: no match calendar data(table id=weekdays) found, maybe fx.com change its site html'!\n";
    }
}

我正在维护一个网站,该网站具有从另一个/外部网站提取表值然后解析它以插入我们的数据库的功能。

我必须更改 $pattern 的值,但我不能,因为我不知道这些符号是什么意思..

十分感谢你的帮助..

4

3 回答 3

4

这称为正则表达式,您可以在此处了解更多信息:http ://www.regular-expressions.info/

/.*?/ims意思是“匹配任何字符,如果有的话(非贪婪)”。

于 2012-12-13T06:37:46.763 回答
3

那是正则表达式中的通配符。

(<table.*?id=\"weekdays\".*)

/./s 表示任何字符

*表示0次或多次

所以/.*/s意味着“匹配任何字符0次或更多次”

细绳 :hello , now this is some garbage , world. And this is a long sentence which ends in world

hello.*world将匹配整个字符串。

参见示例:http ://regexr.com?334em

并且/.*?/s表示“匹配任何字符 0 次或更多次,但非贪婪匹配,即返回最早的匹配项(此处:零长度字符串)。

/hello.*?world/s只会匹配hello , now this is some garbage , world,因为它是最小的非贪婪匹配。

看到相同的例子有区别: http ://regexr.com?334ep

ims是标志im并且s

你可以在这里阅读它们:PHP:regex patterns Docs中可能的修饰符

于 2012-12-13T06:41:04.983 回答
1

http://weblogtoolscollection.com/regex/regex.php

http://webcheatsheet.com/php/regular_expressions.php

这些可能对你有帮助

于 2012-12-13T09:09:48.890 回答