inVINCEable Posted July 13, 2007 Share Posted July 13, 2007 Right now I have a story submition app where users can submit their story. Right now, only the title, as well as the links about the user who provided the story are shown. I would like to show a text summary, somewhat like many sites like Digg.com do. I was wondering the best way to go about doing this... Is it recommended to create an addition field in my table called something like "teaser", or is there a php function that can "grab" the first 50 words and display them. Thank you for any help! Quote Link to comment Share on other sites More sharing options...
Xeoncross Posted July 13, 2007 Share Posted July 13, 2007 I just built a Blog system (codexplorer.com) and I made a special row called "teaser" (The post was in another table). However, you can just use some code like this to cut the post off at a certain length... <?php $text = 'this is my text in a string (which is in PHP)'; function shorten_word($string, $length, $end) { return substr($string,0,$length).$end; } print shorten_word($text, 10, '...'); //Output: 'this is my...' ?> Quote Link to comment Share on other sites More sharing options...
inVINCEable Posted July 13, 2007 Author Share Posted July 13, 2007 I just built a Blog system (codexplorer.com) and I made a special row called "teaser" (The post was in another table). However, you can just use some code like this to cut the post off at a certain length... <?php $text = 'this is my text in a string (which is in PHP)'; function shorten_word($string, $length, $end) { return substr($string,0,$length).$end; } print shorten_word($text, 10, '...'); //Output: 'this is my...' ?> Ah, that's great, I wasn't aware of the substr function but that looks like what I'll need! Although, what exactly is the $end in your post? It isn't part of the params for substr, And I think I will also use a primary key to relate the story to the teaser. And I will just put the teaser in a separate table and pull that up when I pull the story up so I do not have to pull up the whole body of the article... I assume that's what you did? Although I tried visitng your site and it won't let me in.. looks interesting and well designed. Quote Link to comment Share on other sites More sharing options...
metrostars Posted July 13, 2007 Share Posted July 13, 2007 $end is what you want put after the summary. eg: ... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.