Jump to content

display so many characters then put ...


jesushax

Recommended Posts

The only problem with using substr() is words may get cut off half way through, if you don't want that to happen you could do something like this:

 

<?php
$puzzle;
$counter = 1;
$words = 15;

$full_article = 'I am an article, blah blah blah. You find the topic that I am based on extremely interesting and you want to read more of me.';

$pieces = explode( ' ', $full_article );

foreach( $pieces as $piece )
{
$counter++;
$puzzle .= $piece . ' ';

if( $counter > $words ) break;
}

$puzzle = rtrim( $puzzle ) . '...';

echo( $puzzle );
?>

 

There are probably better ways of doing it, but it works...

Archived

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

×
×
  • 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.