Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何限制后期提要?_Php_Rss_Feed - Fatal编程技术网

Php 如何限制后期提要?

Php 如何限制后期提要?,php,rss,feed,Php,Rss,Feed,我有一个PHP类,它从RSS提要中获取帖子,如下所示: 一职 二柱图像 三职位描述 4-Post链接到原始 问题是有时文章的描述太长,我需要帮助将描述限制在几个字以内。 include_once(ABSPATH . WPINC . '/feed.php'); $rss = fetch_feed(' RSS URL '); if (!is_wp_error( $rss ) ) : $maxitems = 1; $rss_items = $rss->get_i

我有一个PHP类,它从RSS提要中获取帖子,如下所示:

一职 二柱图像 三职位描述 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;
}
include_once(ABSPATH.WPINC./feed.php');
$rss=fetch_提要('rss URL');
如果(!is_wp_error($rss)):
$maxitems=1;
$rss\u items=$rss->get\u items(0,$maxitems);
endif;
?>

函数清理($result){ $result=修剪($result); 返回$result; } 函数hapus($result){ $result=str_replace(“”,,$result); $result=str_replace(“”,,$result); $result=str_replace(“,”,$result); $result=str_replace(“”,

“,$result); $result=str_replace(“”,,$result); $result=str_replace(“”,,$result); $result=str_replace(“”,,$result); $result=str_replace(“”,,$result); $result=str_replace(“”,,$result); $result=str_replace(“”,,$result); $result=str_replace(“

”、“

”、$result); $result=修剪($result); 返回$result; }
您知道可以将数组作为参数传递给str\u replace吗?请使用substr()限制描述