I am trying to fetch this from a file:
BEGIN_SEREFERRALS 2 google 13 15 search 2 2 END_SEREFERRALS
I use this function:
function getTextBetweenSEO($file)
{
$pattern = "/BEGIN_SEREFERRALS\s(.*)\sEND_SEREFERRALS/i";
preg_match_all($pattern, $file, $matches);
print_r($matches);
exit();
return $matches[1];
}
What I have printed is this:
Array ( [0] => Array ( ) [1] => Array ( ) )
why does the regular expression fails
you can try with this regex :
$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 For pattern on blob text data:
$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
)
)