سؤال

I am getting a div that is appearing in the output from calling a RSS feed. It is ignoring my attempts to wrap it in a paragraph tag and pushes the data out to the 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; ?>

Here is the html output:

<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>

Why does the description call add a div tag and not get wrapped in the paragraph tag?

هل كانت مفيدة؟

المحلول

That is not a problem of SimplePie... well, not directly. Try to test this html-block:

    <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>

You will see that here the behaviour is the same. The problem is, that the post you get from simplepie is encapsulated in a DIV. And inserting a DIV into a paragraph results in a seperation of both.

So you could try to delete the enclosing DIV in PHP with a regexp or with jQuery, for instance.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top