-1

我正在尝试从文件中获取它:

BEGIN_SEREFERRALS 2 google 13 15 search 2 2 END_SEREFERRALS

我使用这个功能:

     function getTextBetweenSEO($file)
{
    $pattern = "/BEGIN_SEREFERRALS\s(.*)\sEND_SEREFERRALS/i";
    preg_match_all($pattern, $file, $matches);
    print_r($matches);
    exit();
    return $matches[1];

}

我打印的是这样的:

Array ( [0] => Array ( ) [1] => Array ( ) )

为什么正则表达式失败

4

1 回答 1

0

你可以试试这个正则表达式:

$pattern = "^BEGIN_SEREFERRALS(.*)END_SEREFERRALS^";

Array
(
    [0] => Array
        (
            [0] => BEGIN_SEREFERRALS 2 google 13 15 search 2 2 END_SEREFERRALS
        )

    [1] => Array
        (
            [0] =>  2 google 13 15 search 2 2 
        )
)

FIX 对于 blob 文本数据的模式:

$pattern = "/BEGIN_SEREFERRALS(.*)END_SEREFERRALS/";

getTextBetweenSEO("jsdfhksdjhskjfdsjfhsdkjfhBEGIN_SEREFERRALS 2 google 13 15 search 2 2 END_SEREFERRALSjklajdakldjaslkdjakldjalkdjalksdj")

Array
(
    [0] => Array
        (
            [0] => BEGIN_SEREFERRALS 2 google 13 15 search 2 2 END_SEREFERRALS
        )

    [1] => Array
        (
            [0] =>  2 google 13 15 search 2 2 
        )
)
于 2012-06-12T09:21:20.427 回答