如何限制发布信息?

时间:2013-08-12 17:54:45

标签: php rss feed

我有一个PHP类,可以像这样从RSS提要中获取帖子:

1-Post Title 2-post图像 3-post描述 4-post链接到原始

问题是有时后期描述太长了,我需要帮助将描述限制为几个字。

include_once(ABSPATH . WPINC . '/feed.php');
    $rss = fetch_feed(' RSS URL ');
     if (!is_wp_error( $rss ) ) :
    $maxitems = 1;
    $rss_items = $rss->get_items(0, $maxitems);
    endif;
    ?>
    <?php if ($maxitems == 0) echo 'No items';
    else
    foreach ( $rss_items as $item ) : ?>
    <div id="deals">
    <b><a href="<?php echo Clean($item->get_permalink()); ?>" rel="nofollow" target="_blank"><?php echo $item->get_title(); ?></a></b>
    <?php echo hapus(Clean($item->get_content())); ?>
    <p style="text-align:center;bottom:0;"><a title="Order <?php echo $item->get_title(); ?>" href="<?php echo Clean($item->get_permalink()); ?>" rel="nofollow" target="_blank"><img src="<?php bloginfo('template_url');?>/images/check.jpg" alt="<?php echo $item->get_title(); ?>" /></a></p>
    </div>
    <div class="clear"></div>
    <?php endforeach; ?>
    function Clean($result) {

$result = trim($result);
return $result;
}
function hapus($result){
$result = str_replace('<tbody>', '',$result);
$result = str_replace('<tr>', '',$result);
$result = str_replace('<td>', '<p>',$result);
$result = str_replace('</td>', '</p>',$result);
$result = str_replace('</tr>', '',$result);
$result = str_replace('</tbody>', '',$result);
$result = str_replace('<strike>', '',$result);
$result = str_replace('</strike>', '',$result);
$result = str_replace('<table>', '',$result);
$result = str_replace('</table>', '',$result);
$result = str_replace('</p></p>', '</p>',$result);

$result = trim($result);

return $result;
}

0 个答案:

没有答案
相关问题