How to display certain number of words from a record?
Posted by
om 15 May, 2009
I got good php tutorial to display certain number of words from database; in place of Database record you can use any other regular string.
View Code PHP
<?php $text = $row_recap['text']; if (strlen($text) > 300) { $ext = "... <a href='readmore.php'>read more</a>"; } else { $ext = ""; } function elliStr($s,$n) { for ( $x = 0; $x < strlen($s); $x++ ) { $o = ($n+$x >= strlen($s)? $s : ($s{$n+$x} == " "? substr($s,0,$n+$x) . "..." : "")); if ( $o!= "" ) { return $o; } } } echo (elliStr("$text", 300)) . $ext; ?> |
Categories :
Easy PHP

Comments
No comments yet.