Last active
April 12, 2017 01:45
-
-
Save brcontainer/84c4c1fa213d2508590dd6eb70ac4dfb to your computer and use it in GitHub Desktop.
Get images in CDATA (FEED/RSS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* http://pt.stackoverflow.com/a/197684/3635 | |
*/ | |
$imagem = array(); | |
$items = simplexml_load_file("http://cidades.gov.br/ultimas-noticias?format=feed&type=rss")->channel->item; | |
$doc = new DOMDocument; | |
foreach($items as $item) { | |
//Converte o objeto para string | |
$desc = (string) $item->description; | |
//Faz o parse da string html para DOMElement | |
if ($doc->loadHTML($desc)) { | |
//Pega todas tags img | |
$imgs = $doc->getElementsByTagName('img'); | |
//Verifica se existe ao menos uma imagem | |
if ($imgs->length) { | |
//Salva a imagem no array | |
$imagem[] = $imgs->item(0)->getAttribute('src'); | |
} | |
} | |
} | |
var_dump($imagem); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment