Full-service Internet Marketing & Web Development
Recent Posts

Sponsors
![]() |
Creating Abstracts from Full ArticlesCode 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);
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments

