note 70202 deleted from function.str-word-count by sobak
| From: | sobak@php.net | Date: | Sat, 10 Dec 2016 11:14:40 +0000 |
| Subject: | note 70202 deleted from function.str-word-count by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208426@lists.php.net to get a copy of this message | ||
Note Submitter: Aurelien Marchand
----
I found a more reliable way to print, say the first 100 words and then print elipses. My code goes
this way;
<?php
$threshold_length = 80; // 80 words max
$phrase = "...."; // populate this with the text you want to display
$abody = str_word_count($phrase,2);
if(count($abody) >= $threshold_length){ // gotta cut
$tbody = array_keys($abody);
echo "<p>" . substr($phrase,0,$tbody[$threshold_length]) . "... <span
class=\\"more\\"><a href=\\"?\\">read more</a></span>
</p>\\n";
} else { // put the whole thing
echo "<p>" . $phrase . "</p>\\n";
}
?>
For any questions, com.iname@artaxerxes2