note 70202 added to function.str-word-count

From: Date: Fri, 06 Oct 2006 16:06:01 +0000
Subject: note 70202 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-118132@lists.php.net to get a copy of this message
I found a more reliable way to print, say the first 100 words and then print elipses. My code goes this way; $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 ---- Server IP: 66.207.199.35 Probable Submitter: 209.202.82.139 ---- Manual Page -- http://www.php.net/manual/en/function.str-word-count.php Edit -- https://master.php.net/note/edit/70202 Del: integrated -- https://master.php.net/note/delete/70202/integrated Del: useless -- https://master.php.net/note/delete/70202/useless Del: bad code -- https://master.php.net/note/delete/70202/bad+code Del: spam -- https://master.php.net/note/delete/70202/spam Del: non-english -- https://master.php.net/note/delete/70202/non-english Del: in docs -- https://master.php.net/note/delete/70202/in+docs Del: other reasons-- https://master.php.net/note/delete/70202 Reject -- https://master.php.net/note/reject/70202 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118132) next »