Jump to content

Displaying first X words from database?


echoninja

Recommended Posts

I have been trying to find a tutorial on how to display the first X words from a database entry, like google does with search "..."'s
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]PHP: Hypertext Preprocessor
PHP is a server-side HTML embedded scripting language. It provides web developers
with a full suite of tools for building dynamic websites: native APIs to ...
[/quote]

How can this be acheived?
Link to comment
Share on other sites

Feel free to copy/paste.

function trimString($str, $newlength) {
if (strlen($str) > $newlength) {
$newlengthwithdots = $newlength - 3;
$newstring = substr($str, 0, $newlengthwithdots);
$newstring .= "...";
} else {
$newstring = $str;
}
return $newstring;
}

*edit*
Sorry if the indent is confusing, I'm not sure how to indent on these forums.
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.