1
private function pageScrape( $url )
{
    $page_stream = file_get_contents( $url );
    $pattern = '/<link\s+(?=[^>]*rel="(?:[Ss]hortcut\s)?[Ii]con"\s+)(?:[^>]*href="(.+?)").*/>/';
    preg_match( $pattern, $page_stream, $matches );
    print_r( $matches );
    // echo $page_stream;
}

エラーが発生します:

警告: preg_match() [function.preg-match]: 行16の/home/foo/public_html/foo/source/class.ControlBookmark.phpの不明な修飾子 '>'

pcre での PHP.net リファレンス

http://php.net/manual/en/reference.pcre.pattern.syntax.php

4

2 に答える 2

2

$pattern次のように、正規表現パターン変数で正規表現の境界/区切り記号を使用します。

$pattern = '#<link\s+(?=[^>]*rel="(?:[Ss]hortcut\s)?[Ii]con"\s+)(?:[^>]*href="(.+?)").*/>#';
于 2012-05-23T22:06:19.220 に答える
1

問題は、式の末尾にあるエスケープされていないスラッシュが原因です。代わりにこれを試してください:

$pattern = '/<link\s+(?=[^>]*rel="(?:[Ss]hortcut\s)?[Ii]con"\s+)(?:[^>]*href="(.+?)").*\/>/';
于 2012-05-23T22:11:03.770 に答える