I am working on my PHP script to scrapping the data from the website. On the day 1 to day 7, if the flag is 0 I want to check on the times to see if the time is less than 12:00 AM
then I want to use flag = 1
Example: The time 10:00 PM
and 11:59 PM
which is less than 12:00 AM
so i can use flag = 1
Here is the code:
if($day>=0 && $day <= 7)
{
$flag=0;
if($day >= 1)
{
if ($flag == 0)
{
print_r($show_times);
}
}
}
Here is the results:
Array ( [0] => 22:00 [1] => 03:00 [2] => 04:00 [3] => 06:00 [4] => 08:00 [5] => 10:00 [6]
=> 11:00 [7] => 12:00 [8] => 13:00 [9] => 13:55 [10] => 14:25 [11] => 14:55 [12]
=> 16:55 [13] => 18:10 [14] => 18:40 [15] => 19:00 [16] => 19:30 [17] => 20:00 [18] => 20:55 [19]
=> 21:55 [20] => 23:10 [21] => 00:40 [22] => 01:00 [23] => 01:30 [24] => 02:00 ) 10:00 PM KSW 39
Here is the full code:
<?php
function get_shows($day,$channel_id, DateTime $dt, $today = false)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_USERAGENT => '',
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_SSL_VERIFYPEER => false
));
$date = $dt->format('Y-m-d');
$tz = $dt->getTimezone();
$now = new DateTime('now', $tz);
$today = $now->format('Y-m-d');
$shows = array();
$url = 'https://www.example.com/scrip.php?date=' . $date;
curl_setopt($ch, CURLOPT_URL, $url);
$body = curl_exec($ch); //get the page contents
$channel_row = $row_channels[0][0]; // Woksepp: 0 = First row.
$pattern23 = "/<a class=\"prog\" href=\"(.*?)\">.*?<span class=\"time\">(.*?)<\/span>.*?<span class=\"title\" href=\"\#\">(.*?)<\/span>.*?<span class=\"desc\">(.*?)<\/span>/s";
preg_match_all($pattern23, $channel_row, $d);
$show_times = $d[2];
//test this
if($day>=0 && $day <= 7)
{
$flag=0;
if($day >= 1)
{
if ($flag == 0)
{
print_r($show_times);
}
}
}
}
What I'm expecting to do is I want to check if the time show 22:00
or whatever it is that comes before the middle night time 00:00
, then I want to set the flag to 1 so I can skip the time in the array.
Can you please show me an example how I can check the time between 22:00
and 23:59
to see if the time is less than 00:00
so I can use flag = 1
under the if statement?
Try the following:
if($day >= 1)
{
foreach($show_times as $show_time)
{
if(strtotime($show_time) < strtotime('12:00'))
{
$flag=1;
}
}
}
This will check if the time is less than noon
and set the $flag
to 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.