Im trying to search for two HTML tags, and also grab everything in between. When I try each of the tags separately it finds them fine, so I know that they are spelled right and exist. The problem I think is with the pattern, can someone please help me with it.
Everything I research online seems to go right over my head. So if you could please explain how your pattern works, that would be awesome!
See code below, and if you have any questions feel free to ask.
Thanks for your time:)
<?php
$date= date(Y)."/".date(n)."/".date(j);
$address= "http:www.example.com/".$date;
$text_page = file_get_contents("$address");
$searchfor1 = '<li id="menuSynchronizeSwitch">';
$searchfor2 = '<li id="footerPrevWeek';
header('Content-Type: text/plain');
$pattern1 = preg_quote($searchfor1, '/');
$pattern2 = preg_quote($searchfor2, '/');
$pattern = "/^.*$pattern1.*\r*$pattern2.*\$/m";
if(preg_match_all($pattern, $text_page, $matches)){
echo "Found matches:\n";
echo implode("\n", $matches[0]);
}
else{
echo "No matches found";
}
?>
Try using
$pattern = '/\<li id\="menuSynchronizeSwitch"\>.*\<li id\="footerPrevWeek/si';. Note the/s, which allows the dot to match newlines, which I suspect is what is causing this to fail.