Can anybody post me the function to remove off the long text to lil bit short like into 100 words only?? suppose there is a long text more than 200 words then that function should only show 100 words and at the last should show ... and link for more thanks
Here is an example: <? //test it with some short text $text = "some short text that doesn't need to be cut"; cut_text($text); printf("<hr />"); //now something long enough to be cut $text = ''; for($i = 0; $i < 255; $i++) $text .= "long "; cut_text($text); function cut_text($text, $words = 200) { $c = 0; $len = 0; for($i = 0; $i < strlen($text); $i++) { if($text{$i} == ' ') $c++; if($c == $words) { $len = $i; break; } } if($len) printf("<div id='cut_text'>%s<br /> <div style='display: none' id='other_text'>%s</div> <input type='button' value='Show More' onclick=\"document.getElementById('other_text').style.display='inline'\"> </div>", substr($text, 0, $len), substr($text, $len, strlen($text)-$len)); else printf("<div id='cut_text'>%s</div>", $text); } ?> PHP: You can change the number of words after which the script will cut the text, just pass second argument to cut_text(). You owe me at least a beer for that one