mercredi 17 janvier 2018

PHP Decrease Code Character Count

I have a snippet of code that reads an RSS feed and displays the first 5 results.

It all works as expected, however in order to suits my needs the total amount of characters need to be no more than 350. Currently it's at 413.

Is there any way to "minify" this code so that the functionality remains the same, but it's no more than 350 characters.

Code;

<?php
$rss_feed = simplexml_load_file("http://ift.tt/2mF5Wju");
if(!empty($rss_feed)) {
    $i=0;
    foreach ($rss_feed->channel->item as $feed_item) {
        if($i>=5) break;
        ?>
        <p><a href="<?php echo $feed_item->link; ?>"><?php echo $feed_item->title; ?></a></p>
        <p><?php echo implode(' ', array_slice(explode(' ', $feed_item->description), 0, 14)) . "..."; ?></p>
        <?php       
        $i++;   
    }
}
?>

Notes;

  • I need to echo the title as a html link
  • I need the title and description to be on individual paragraphs
  • I need to truncate the description

Any advice is appreciated.

Aucun commentaire:

Enregistrer un commentaire