Jump to content

Output a set number of words


Mr Chris

Recommended Posts

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?

Thanks
Link to comment
Share on other sites

Two examples:
[code]

<?php

$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

?>

[/code]
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.