I'm working with wordpress. I tried to display rss feeds from different sites. I put the url for each site as post content with category name rssfeed. Code for rss feed is given below.
<?php // Get RSS Feed(s)
$arr = array('posts_per_page' => '10', 'category_name'=>'rssfeed', 'order' => 'ASC', 'category_id' =>21);
$rssfeed = get_posts($arr);
foreach($rssfeed as $rf)
{
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( $rf->post_content);
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 2 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<ul>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'my-text-domain' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li><div class="news">
<div class="row">
<div class="col-sm-6 news_content">
<h3><strong><a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">
<?php echo esc_html( $item->get_title() ); ?>
</a></strong></h3><br />
<?php $cont=esc_html( $item->get_content() ); $vtag=substr($cont,0,100);
/* $out=strip_tags($vtag,'<a>');
$result=str_replace('<span>',"Peter",$out);*/
// var_dump($vtag);
// $result=preg_replace('/ <p>/', ' ',$vtag);
remove_accents ($vtag);
?>
<p><?php echo $vtag;?></p>
</div>
</div>
</div></li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
When I'm displaying a rss feed I'm getting the string like this as short content.
<p>EGYPTAIR has signed a five-year contract with air transport communications specialist
<div class="node-body magazine_issue-body"></div> <div class="fiel
ANA May Order A380s
<div class="node-body article-body"><p>All Nippon Airways has reportedly agree
<span>IATA welcome the historic COP 21 Paris Agreement which will provide additional
I would like to get the string without <p>, <span>, <div class="node-body magazine_issue-body"></div>, <div class="fiel etc.
I tried preg_replace()
, str_replace()
, and strip_tags()
Any other way?