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

?>

Link to comment
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...'

?>

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.