Jump to content

Generating a story summary on the fly?


inVINCEable

Recommended Posts

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!

 

 

Link to comment
https://forums.phpfreaks.com/topic/59838-generating-a-story-summary-on-the-fly/
Share on other sites

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...'

?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.