【问题标题】:div automatically added in $item->get_description(); using simplepie$item->get_description()中自动添加的div;使用简单派
【发布时间】:2012-06-06 20:07:38
【问题描述】:

我在调用 RSS 提要时得到一个出现在输出中的 div。它忽略了我尝试将其包装在段落标签中并将数据推送到 div 中。

foreach ($feed->get_items(0 , 3) as $item):
    $feedDescription = $item->get_content();
    $image = returnImage($feedDescription);
    $image = scrapeImage($image);
    $image_url= $item->get_permalink();
    $description = $item->get_description();
?>
        <div class="item">
            <h4><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
            <div class="image-box"><?php echo '<a href="' . $image_url . '"><img src="' . $image . '" /></a>'."\n";?></div>
            <p><?php echo $description ?></p>
            <p><a href="<?php echo $item->get_permalink(); ?>">Continue Reading</a></p>   
        </div>
 
    <?php endforeach; ?>

这里是html输出:

<div class="item">
    <h4><a href="#">Lorem Ipsum</a></h4>
    <div class="image-box"><a href="#"><img src="image.jpg"></a>
</div>
<p></p>

<div>Lorem Ipsum description [...]</div>

<p></p>
<p><a href="#">Continue Reading</a></p>   
</div>

为什么描述调用添加了一个div标签而不是被包裹在段落标签中?

【问题讨论】:

    标签: rss feed feedparser simplepie


    【解决方案1】:

    这不是 SimplePie 的问题……嗯,不是直接的。 尝试测试这个 html 块:

        <div class="item">
            <h2><a href="http://#">Title</a></h2>
            <p><div><span>Description</span></div></p>
            <p><small>Posted on TODAY</small></p>
        </div>
    

    您会看到这里的行为是相同的。 问题是,您从 simplepie 获得的帖子被封装在 DIV 中。在段落中插入 DIV 会导致两者分离。

    因此,您可以尝试使用正则表达式或 jQuery 删除 PHP 中的封闭 DIV。

    【讨论】:

    • 我能够使用 jquery 以编程方式删除 div。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 2021-03-31
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多