Jump to content

Archived

This topic is now archived and is closed to further replies.

Mr Chris

Output a set number of words

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.