0
I’m pulling the rss
of instagram
of a market profile, but I want it at 10:00 in the morning 00:00
(midnight) it displays the photo of the first post, and that from the 00:01
until 9:59
in the morning it displays any illustration image.
I’m trying to use the non-server time so it doesn’t go wrong. What I tried so far worked only the display during the day, but when midnight comes it displays the error message. That is the code:
<?php
$url = "https://www.instagram.com/comprebemsupermercado/?__a=1";
$data = file_get_contents($url);
$arrData = json_decode($data, true);
$instagram_photos = $arrData['graphql']['user']['edge_owner_to_timeline_media']['edges'][0]['node']['display_url'];
echo "<meta http-equiv='refresh' content='1800'; url='index.php'>"; //atualiza a cada 30 minutos
echo "<link rel='stylesheet' type='text/css' href='style.css?version=330'>";
echo "<div class='fundo'>";
echo "</div>";
// DEFINE O FUSO HORARIO COMO O HORARIO DE BRASILIA
date_default_timezone_set('America/Sao_Paulo');
// CRIA UMA VARIAVEL E ARMAZENA A HORA ATUAL DO FUSO-HORÀRIO DEFINIDO (BRASÍLIA)
$hr = date(' H:i ', time());
if($hr >= 24 && $hr < 10) {
$resp = "<img class='logo' src='logo.jpg' alt=''/>";}
else if ($hr >= 10 && $hr < 24 ){
$resp = "<img class='img-responsive' src='{$instagram_photos}'/>";}
else {
$resp = "Erro";}
echo "$resp";
?>
And this is the CSS:
.img-responsive{
position: absolute;top: 0;
left: 200px;
top: 100px;
width: 900px;
height: 900px;
}
.fundo{
position: absolute;top: 0;
width: 1920px;
height: 1080px;
}
.logo{
position: absolute;top: 0;
left: 200px;
top: 100px;
width: 900px;
height: 900px;
}
A tip dear Virgilio, the cast
(int)
is dispensable in this type of comparison, php itself does it, I think it would be only interesting if the goal was to achieve micro-optimization, as a loop that will process about 40,000 comparisons like this in "ifs". ;)– Guilherme Nascimento
a hint if I want a comparison with the text type neh @Guilhermenascimento and if I want to force the type to be a number, because it returns a text type ...
– novic
But the cast or comparison with operators of smaller and larger will be the same effect to compare numbers, understand? I’m talking about the specific case and not "all" types of comparison ;)
– Guilherme Nascimento
But I want so @Guilhermenascimento ... I want him to do the
cast
. One comes and speaks in loose comparison, another comes and contexts, here no one is satisfied in wisdom.– novic
@Virgilionovic gave error in the two points between the hourly numbers
– jose113
It depends on what you did @jose113 ??? how you did it and what went wrong!
– novic
date_default_timezone_set('America/Sao_paulo'); // CREATES A VARIABLE AND STORES THE CURRENT TIME OF THE DEFINED TIME ZONE (BRASÍLIA) $hour = (int)date('G'); if ($hour >= 0 && $hour < 09:59){ $Resp = "<img class='logo' src='logo.jpg' alt='/>"} Else if ($hour >= 10:00 && $hour < 0:00 ){ $Resp = "<img class='img-Responsive' src='{$instagram_photos}'/>";} Else { $Resp = "Error";} echo "$Resp"; ;?>
– jose113
looks like you wrote
$hour >= 0 && $hour < 09:59
just put<10
if you didn’t follow my reply @jose113 o if ta pronto é só colocar as duas imagens dentro do cochetes– novic
@Virgilionovic Yes, even now following your answer did not work
– jose113
Let’s go continue this discussion in chat.
– novic