SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limiting how much text is displayed @ once[more ...]

    When I grab an entry from MySQL I need to check if it exceeds 522 characters && exceeds 6 carriage returns. If it exceeds either of these conditions I have to truncate the text so it meets the conditions and have a More... link that once clicked will lead to the full text.

    Not sure how to go about this. Any guidance would be appreciated.
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Do you want to use PHP for this?
    If so strlen() and substr() will help you. I am not totally sure about the carriage return but try:

    Carriage return is "\r", isn't it?

    PHP Code:
    // check the length and the amount of carriage returns
    if ((strlen($text) > 522) || (count(explode("\r"$text)) > 6)) {
       
    // use substr and append the 'more' link.
       
    $text substr($text0522). ' more';


  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Carriage return is \n

    -Sam
    Sam Hastings

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd change (count(explode("\r", $text)) to substr_count($text, "\n")
    TuitionFree — a free library for the self-taught
    Anode Says...Blogging For Your Pleasure

  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you do use \n, make sure to convert \r\n and \r to \n before doing anything with it, because of differences between mac (\r), windows (\r\n) and unix (\n) new lines.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •