在函数php中,将字符输出限制为12个字


Limit characters output to 12 word in function php

再次需要一些帮助,这里有一个函数可以返回文本内容并阅读wordpress:中的更多链接

function whisper_entry_contentoffer1()
{
global $whisper;
// Check on singular pages
$is_single = is_singular() && !is_page_template( 'tpl/blog.php' ) && !is_page_template( 'tpl/blog-boxes.php' );
// Allow to config via global variable
if ( isset( $whisper['is_single'] ) )
    $is_single = $whisper['is_single'];
if ( $is_single )
{
    echo '<div class="entry-content">';
    the_content();
    wp_link_pages( array(
        'before'      => '<p class="pages">' . __( 'Pages:', 'whisper' ),
        'after'       => '</p>',
        'link_before' => '<span>',
        'link_after'  => '</span>',
    ) );
    echo '</div>';
    return;
}
// Archives & Blog pages
// Display type
$display = fitwp_option( 'blog_display' );
// Allow to config via global variable
if ( isset( $whisper['blog_display'] ) )
    $display = $whisper['blog_display'];
if ( !$display )
    $display = 'content';
echo '<div class="entry-summary">';
// Excerpt
if ( 'excerpt' == $display )
{
    the_excerpt();
    return;
}
$more_text = whisper_more_text2();
// Post content before more tag
if ( 'more' == $display )
{
    if ( is_page_template( 'tpl/blog.php' ) || is_page_template( 'tpl/blog-boxes.php' ) )
    {
        global $more;
        $more = false;
    }
    the_content( $more_text );
    wp_link_pages( array(
        'before'      => '<p class="pages">' . __( 'Pages:', 'whisper' ),
        'after'       => '</p>',
        'link_before' => '<span>',
        'link_after'  => '</span>',
    ) );
}
else
{
    whisper_content_limitoffer1( whisper_content_length(), $more_text );
}
echo '</div>'; // .entry-summary
}

现在我需要将输出文本限制为12个单词。有什么建议或灵魂吗?!

谢谢。。。

这个?用字符串替换$string

echo implode(" ",array_splice(explode(" ",$string),0,20));