gpt4 book ai didi

php - SimplePie 可以从提要中抓取图像吗

转载 作者:行者123 更新时间:2023-12-05 09:24:45 24 4
gpt4 key购买 nike

我正在使用这个 simplepie,我已经将文件上传到我的主机。除了一件事,一切似乎都运行良好。我从中获取提要的博客中有图像,当我使用 simplepie 查看提要时,图像不显示。当我使用 simplepie 查看博客时,有没有办法让图像显示出来?

好的,对不起,我是新手。我只是直接使用网站上的代码来尝试查看博客。我会把代码放在底部。所以是的,就像我说的那样,我只是想让图像显示在我正在阅读的博客上。除此以外,一切都很好。

--- 标题信息 ---

<?php

// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
require_once('simplepie.inc');

// We'll process this feed with all of the default options.
$feed = new SimplePie();

// Set the feed to process.
$feed->set_feed_url('http://wordpress.homickdesign.com/feed/');

// Run SimplePie.
$feed->init();

// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();

// Let's begin our XHTML webpage code. The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag.
?>

---代码---

<h2><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_description(); ?></a><br />
<span>Latest news from Robert Homick</span></h2>

<?php
$c=1;
foreach ($feed->get_items() as $item):
if($c <= 3){
?>

<p><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a><br />
<?php echo $item->get_description(); ?><br />
<span>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></span><br />
<?php $c++;?>


<?php } endforeach; ?>

最佳答案

是的,您可以调用 get_content() 并且整个帖子或包含在提要中的帖子部分将输出到屏幕,包括所有 HTML 标记。如果你想拉出帖子中的第一张图片,你必须做更多的工作,这就是我一直在做的。

$htmlDOM = new simple_html_dom();
$htmlDOM->load($item->get_content());
$image = $htmlDOM->find('img', 0);
$html .= '<img src="thumbnail.php?file=' . $image->src . '&maxw=300&maxh=300" border="0" />';

该片段来 self 当前的小项目,使用 simple_html_dom 和我从 Internet 上获得的另一个脚本来动态调整图像大小。如果你只是想显示图像而不调整它的大小 $image->src 是 URL。我认为将来可能会将这样的功能添加到 SimplePie 中或添加到 SimplePie 中,但与此同时,只需四行代码即可显示来自提要的项目的第一张图像。

关于php - SimplePie 可以从提要中抓取图像吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9628590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com