【问题标题】:Limit characters output to 12 word in function php在函数php中将字符输出限制为12个字
【发布时间】:2014-08-28 11:59:44
【问题描述】:

再次需要一点帮助,这是一个返回文本内容并在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 个字。有什么建议或意见吗?!

谢谢...

【问题讨论】:

标签: php wordpress output


【解决方案1】:

这个?用你的字符串替换 $string

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

【讨论】:

    猜你喜欢
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 2020-07-07
    • 2014-01-25
    • 2014-10-14
    相关资源
    最近更新 更多