View Full Version : showing info
robojob
01-26-2006, 09:22 PM
if i have a field in my database that contains a large amount of text is there a way of showing for example the first coupld of words??
arnyinc
01-26-2006, 09:52 PM
It's probably to do it better with your select statement from your database. This is for oracle, but should work in other DB's as long as substr and instr are supported.
The instr function finds the second instance of a space. The substr takes all the text from the first position up until the location of the second space.
select substr(yourfield, 0, instr(yourfield, ' ', 1, 2)) from yourtable;
TheShaner
01-26-2006, 09:53 PM
http://www.codingforums.com/showpost.php?p=383523
This is in the PHP Snippet page, last page, called Function: TrimByWords() (http://www.codingforums.com/showthread.php?t=74317)
I gave a link to the Marek_mar's implementation since it's a bit more efficient. Notice the last line here:
print wordswrap($text, 6);
Change the above number to whatever number of words you want displayed before displaying the three dots (...) afterwards.
-Shane
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.