Jump to content

[SOLVED] Limit Output


Bricktop

Recommended Posts

Hi all,

 

I wonder if someone could tell me how I limit MySQL output? Essentially, I have a script that outputs some "Latest News" text - on my main "News" page I would like this output to be limited to say the first 50 words and then a "Read More" link will be clickable to take the reader to the full story.

 

Just wondered on the syntax required to limit the output to the first x amount of words.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/125609-solved-limit-output/
Share on other sites

function limit_words($str, $limit, $extension=""){
$words = explode(" ", $str, $limit + 1); //We plus 1 because limiting the explode causes the remaining words to be placed in the last key.
array_pop($words);
return implode(" ", $words).$extension;
}

echo limit_words("Hey this will be limited to 5 words!", 5, "... Read More");

Link to comment
https://forums.phpfreaks.com/topic/125609-solved-limit-output/#findComment-649421
Share on other sites

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.