Jump to content

Displaying part of a field content


nduaj

Recommended Posts

hello,

I recently developed a news website, but i have a questions:

on the home page, i want to show just previews of the news (mabe 50 - 100 words) from the story field of my news table in the databsae.

 

my question is, how do i display on 50 words from the content of the field table.

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/90661-displaying-part-of-a-field-content/
Share on other sites

There's probably a better way of doing this, but you could explode your current string by a space, creating an array of the words in the string.  Then you could loop through and echo the first 50 array values:

 

$string = $r->content; // Content pulled from the database

$temp = explode(" ", $string); // Explode the content string

for($i=0; $i<50; $i++) {

echo $temp[$i];

}

 

Like I said, there's probably a much easier way - I just don't know about it!

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.