WordPress — PHP DOMDocument: getElementsbyTagName (‘img’) не работает

Я пытаюсь получить тег img внутри канала в WordPress. Вот код, который я использую:

<?php
/* specify the source feed   */     $rss = fetch_feed('http://www.anobii.com/rss_shelf?s=01fe251a6c442bbf8a');
/* checks obj. is created    */     if (!is_wp_error( $rss ) ) :
/* specify number of items   */     $maxitems = $rss->get_item_quantity(5);
/* create an array of items  */     $rss_items = $rss->get_items(0, $maxitems);
endif;
?>
<ul>
<?php if ($maxitems == 0) echo '<li>Content not available</li>';
else
// Loop through each feed item and display each item as a hyperlink.
$firstContent = null;
$firstIsSet = false;
foreach ( $rss_items as $item ) : ?>
<?php
if (!$firstIsSet) {
$firstContent = $item->get_content();
$firstIsSet = true;
}
?>
<?php $doc = new DOMDocument();
@$doc->loadHTML($firstContent);
$imgs = $doc->getElementsbyTagName('img');
$res = $imgs->item(0)->getAttribute('src');
$highres = str_replace("type=3", "type=4", $res);
?>
<li>
<a href="<?php echo $item->get_permalink(); ?>" title="<?php echo esc_html( $item->get_title() ); ?>" rel="external"><?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<img src="<?php print_r($highres); ?>" style="float:right">

get_title() а также get_permalink работают нормально. Но print_r($highres); ничего не делает..

Может быть, проблема в том, что RSS-канал несколько сломан (см. fetch_feed ссылка на сайт)..?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector