"Show more" script in PHP

Discussion in 'PHP' started by MV07SMV, Jul 14, 2009.

  1. #1
    Hi,

    I'm trying to make a news section on my home page to display text and want to find a script so that it limits the number of characters displayed but then has an option to click and display more and then expands once clicked.

    My first attempt at this in php so not sure where to start.

    Hope this is the right place to ask, was trying to use functions in PHP

    Please help !

    thanks
     
    MV07SMV, Jul 14, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maybe something like this:
    
    $charsAllowed = 50; //Number of characters you want to limit text to
    $myText = "blah"; //You'd have all your text here
    $myTextTrimmed = substr_replace($myText, "", $charsAllowed); //Params: text to operate on, text to replace with, staring point
    
    $more = " <a href=\"location.php\">Read More</a>"; //more link
    $myTextTrimmed .=$more //Add the more link to the trimmed text
    
    PHP:
    Then you echo out $myTextTrimmed wherever you want the shortened version, and $myText wherever you want the full version.

    There might be a better function to trim a string to a certain length, rather than using substr_replace, I am also new to PHP so hopefully somebody can clarify this.
     
    wd_2k6, Jul 14, 2009 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    You would need javascript if you want to show the contents without loading.

    Reference you might need.

    Google for more.
     
    ads2help, Jul 15, 2009 IP
  4. vpdesigns

    vpdesigns Peon

    Messages:
    353
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    vpdesigns, Jul 17, 2009 IP
  5. mioot

    mioot Peon

    Messages:
    169
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    my suggestion use tool tips.To show the rest of content. It will done without reloading the page.
     
    mioot, Jul 17, 2009 IP