2016-08-02 20 views
1

我需要比较字符长度我的Custom Post Type post->content 我已经显示内容限制为200个字。if语句比较the_content()的字符长度;

<?php $content = get_the_content(); 
echo substr($content, 0, 200); ?> 

但是,如果字符超过200个单词,我需要触发某些内容。

类似这样:

if(character_length > 200) , Popup link to display the whole content.

我搜索了StackOverflow的谷歌,但无法找到合适的解决方案。

任何帮助,将不胜感激

回答

1

可以使用strlen功能,找出一个字符串有多长:

if (strlen($content) > 200) { 
    // Popup link to display the whole content... 
}