2016-08-02 67 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... 
}