以下のgetExcerpt()関数を使用して、テキストのスニペットの長さを動的に設定しています。ただし、私のsubstrメソッドは現在文字数に基づいています。単語数に変換したいのですが。関数を分離する必要がありますか、それともsubstrの代わりに使用できるPHPメソッドがありますか?
function getExcerpt()
{
//currently this is character count. Need to convert to word count
$my_excerptLength = 100;
$my_postExcerpt = strip_tags(
substr(
'This is the post excerpt hard coded for demo purposes',
0,
$my_excerptLength
)
);
return ": <em>".$my_postExcerpt." [...]</em>";}
}