-1

我找到了一个用于从网页中获取项目标题的 php 函数,它使用的 reg exp 是,/<div class=\"detail\">(.*?)<p>/si如以下代码所示:和之前没有贪心,但是什么意思?谢谢!/<div class=\"detail\">(.*?)<p><p>/si

    <?php

    // Get the title
    function match_title( $content ) {
         preg_match( '/<div class=\"detail\">(.*?)<p>/si', $content, $result );
         isset( $result ) ? $title = trim( addslashes( $result[1] ) ) : $title = '';
         return $title;
    }

    $url = "http://a.m.taobao.com/i21708516412.htm";
    $item = file_get_contents($url);
    $title=match_title( $item );

    ?>
4

2 回答 2

3

请参阅此处了解所有修饰符:http ://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

i (PCRE_CASELESS)
If this modifier is set, letters in the pattern match both upper and lower case letters.

s (PCRE_DOTALL)
If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

总结一下:换行符匹配并且表达式是无大小写的。

于 2013-05-25T06:50:16.657 回答
0

/si是正则表达式匹配模式

i使正则表达式匹配不区分大小写。

s启用“单行模式”。在这种模式下,点匹配换行符。

请参阅 -正则表达式匹配模式

于 2013-05-25T06:52:31.560 回答