Jump to content


Photo

Displaying first X words from database?


  • Please log in to reply
2 replies to this topic

#1 echoninja

echoninja
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 01 March 2006 - 03:37 AM

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?

#2 rawb

rawb
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 01 March 2006 - 03:48 AM

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.

#3 echoninja

echoninja
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 01 March 2006 - 04:17 AM

great stuff, I can see how it works now :) thanks very much




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users