Jump to content


Output a set number of words

  • Please log in to reply
1 reply to this topic

#1 Mr Chris

Mr Chris
  • Members
  • PipPipPip
  • Advanced Member
  • 336 posts

Posted 30 October 2006 - 02:49 PM

Hi Guys,

In PHP I was wondering:

1) If there is a function which lets me output a set amount of words from a text field in a MYSQL database (and if so can someone can provide a link  ;D )
2) If I have the text saved in the DB as <b>This is the first paragraph<break></b> Is there any way I can get php to say output all the words until you see the first <break> then stop outputting?


#2 alpine

  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 30 October 2006 - 04:42 PM

Two examples:


$string = "abah ashb ashb asadyuci <break>ajkshdkj asduiqw hqwjd </break>sjakj asjkuq";

$parts = explode("<break>",$string);
echo $parts[0]; // output: abah ashb ashb asadyuci

echo join(" ", array_slice(explode(" ", $string), 0, 2)); // output: abah ashb


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users