这是有问题的页面,http://knowgreaterpartnership.com/secrets/.
我们使用的RSS生成器在"事件"提要上插入内联html标记,如<br>
、<i>
和</i>
。
以下是我最终尝试从代码中删除这些位的代码:
<div id="right" class="last">
<h1><?php esc_html_e( 'Buchanan Events', 'Fusion' ); ?></h1>
<article id="jobs">
<?php if ( function_exists( 'fetch_feed' ) ) { ?>
<?php include_once(ABSPATH . WPINC . '/feed.php');
$feed = fetch_feed( 'http://www.bipc.com/rssfeeds/rss.aspx?id=35' );
$feednew = str_replace( array( '<br>', '<i>', '</i>' ), '', $feed );
$limit = $feednew -> get_item_quantity(5);
$items = $feednew -> get_items(0, $limit);
if ( !$items ) {
echo "problem";
}
else {
//everything's cool
foreach( $items as $item ){ ?>
<h2 class="post"><a class="link" href="<?php echo $item -> get_permalink(); ?>" target="_blank"><?php echo $item -> get_title(); ?></a></h2>
<p class="date"><?php echo $item -> get_date( 'F j, Y' ); ?></p>
<hr>
<?php }
} ?>
<?php } ?>
</article>
</div>
我正在尝试使用str_replace()来搜索<br>
、<i>
和</i>
标记,并将它们替换为空,以便使其余的文本流动。
如果我没有使用正确的方法,请告诉我。谢谢
这应该适用于您:
只需使用strip_tags()
,它就会删除所有的html/php标记(包括html注释)。
$feed = strip_tags($feed);