Click to See Complete Forum and Search --> : Display intro text to article with more....button


Megatron
07-05-2006, 07:20 PM
I'm currently pulling out articles from a database but the articles are quite large and when i display more than 3 articles on a single page the page becomes too chaotic with text.

How can only show the first 50 words of the article?

<?php echo $entry; ?> is all i'm using to display the articles and i'm using a straight forward sql statement as well if it makes any difference? :
$sql = "SELECT * FROM php_blog WHERE category='$category' ORDER BY timestamp DESC LIMIT 5";

Thanks

bokeh
07-05-2006, 08:02 PM
Try this:<?php echo implode(array_slice(preg_split('/(?<=\s(?=\w))/', $entry), 0, 50)); ?> Or for more ways to do it check out this thread (http://www.webdeveloper.com/forum/showthread.php?t=111914).

Sheldon
07-05-2006, 11:25 PM
im not sure about words, but charactors is like this


$sql = "SELECT left(entry, 233) as entry FROM php_blog WHERE category='$category' ORDER BY timestamp DESC LIMIT 5";


Im not sure if that is exact

Megatron
07-06-2006, 09:24 AM
Or for more ways to do it check out this thread (http://www.webdeveloper.com/forum/showthread.php?t=111914).

Nice thread! I got it working from some of your code.

$capture = 5;

echo 'START: '.implode(' ', array_slice($words = explode(' ', $text), 0, $capture))."<br>\n";

to be exact!