How to choose what will be displayed from the xml by the php you are reading?

Asked

Viewed 28 times

0

I have this Instagram rss code in XML is on this link: https://rss.app/feeds/wUySUmu0Kiy1c3uL.xml But the part I need is this:

<description>
<![CDATA[
<div> <img src="https://scontent-lga3-1.cdninstagram.com/vp/ef4a583cbe6ef13f207af32ee0780986/5E394ECF/t51.2885-15/e35/p1080x1080/71083885_707708566306382_5421780063674118290_n.jpg?_nc_ht=scontent-lga3-1.cdninstagram.com&_nc_cat=102" style="width: 100%;"> <div>Olha a #quartadopão recheada de delícias com aquele precinho que só a gente tem. #correpracá!</div> </div>
]]>
</description>

What I want to get is just the text, without the tags, that would be:

Look at the #quarter filled with delicacies with that precinct that just the people have. #correpracá!

What I’m trying to do is:

<?php
$instaResult = simplexml_load_file('https://rss.app/feeds/wUySUmu0Kiy1c3uL.xml', NULL, LIBXML_NOCDATA) or die("error");
$instagram_photos = $instaResult->channel->item[0]->enclosure['url'];

$instagram_date = $instaResult->channel->item[0]->pubDate;
echo str_replace('Wed','Quarta',$instagram_date);

$instagram_description = htmlentities((string)$instaResult[0]->channel->item[0]->description);

print $instagram_description;

echo "<meta http-equiv='refresh' content='1800'; url='index.php'>"; //atualiza a cada 30 minutos
echo "<link rel='stylesheet' type='text/css' href=''>";
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)
$hour = (int)date('G');
if ($hour >= 0 && $hour < 10)
{
	// 00:00 até 09:59
	$resp = "<img class='logo' src='logo.jpg' alt=''/>";
}
else
{
	// 10:00 até 23:59
	$resp = "<img class='img-responsive' src='{$instagram_photos}'/>";
}

echo $resp;
?>

Remembering that I’m already pulling the image and date of the last post of this instagram, so the code the most. The part that it pulls the description is:

$instagram_description = htmlentities((string)$instaResult[0]->channel->item[0]->description);

print $instagram_description;

If you can help me, I’d like to thank you!!!

1 answer

-1


Try this :

$texto = '
        <description>
<![CDATA[
<div> <img src="https://scontent-lga3-1.cdninstagram.com/vp/ef4a583cbe6ef13f207af32ee0780986/5E394ECF/t51.2885-15/e35/p1080x1080/71083885_707708566306382_5421780063674118290_n.jpg?_nc_ht=scontent-lga3-1.cdninstagram.com&_nc_cat=102" style="width: 100%;"> 
<div>Olha a #quartadopão recheada de delícias com aquele precinho que só a gente tem. #correpracá!</div> </div>
]]>
</description>';

 $result = trim(strip_tags(str_replace(array("<![CDATA[","]]>"),array("",""),$texto)));
 echo $result;
  • thank you very much! It worked perfectly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.