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
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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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