Jump to content

How do I do this while outputing info?


Dobakat

Recommended Posts

Well I got a website, and I got a function that helps me add the news to the MySql database. On the main page I use PHP to get the 2 newest news. And I put echo"$fetch->news"; Well the $fetch->news does not matter, its just the assigned variable that has the news. The problem is that some news are too long. I only want the first # words to appear, then skip a line and put a link that says 'Read more...' with a link to the article. I am not worrying about the linking, only on how to making it put only 4-5 line of the begining of the news. If I was confunsing in some way, let me know. I hope someone can answer my question.
Link to comment
Share on other sites

Make a function like this (it takes as params the article string and its id to build the link):


[code=php:0]
function fixLength($str, $id){
    $maxChars = 50;
    if (strlen($str)>$maxChars){
        $str= substr($str, 0, $maxChars )."...<br/><a href=\"index.php?article={$id}\">Read more &raquo;</a>";
    }
    return $str;
}
[/code]
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.