Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Creating Abstracts from Full Articles

Code Wizard, 12-30-2006

If you have full articles, but want to make automatic abstracts for them (useful for that "click for more info" concept), check out this handy little snippet of code.

First you have to determine the maximum length you'd like for the abstract.
Then, using substr(), you can grab that much of the string.
Of course, this might be the middle of the word so you can use strrpos() to get the position of the last space.
Then use substr() again to grab everything until that space.

function Abstract($text,$length)
{
$text=substr($text,0,$length);
$lastspacepos=strrpos($text,' ');
return substr($text,0,$lastspacepos);
}

You can call this like:

$abstract=Abstract($full_story_text,255);
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions