Short up text

Discussion in 'PHP' started by Alice24, Mar 11, 2011.

  1. #1
    How can i short up a text from a database and use a read more>>
    for example if i receive from database this
    Fair.Game.2010.LiMiTED.MULTi.1080p.BluRay.x264-LOST  (DISTEL) ; Fair.Game.2010.BRRip.AC3.H264-CRYS(sync:enriqo); Fair.Game.2010.DVDSCR.XViD.Absurdity; Fair.Game.2010.DVDSCR.XViD.AC3-T0XiC-iNK; Fair.Game.2010.DVDSCR.XViD-FooKaS.
    PHP:
    to be more short like this
    Fair.Game.2010.LiMiTED.MULTi.1080p.BluRay.x264-LOST  (DISTEL) ; Fair.Game.2010.BRRip.AC3.H264-CRYS(sync:enriqo); Fair.Game.2010.DVDSCR.XViD.Absurdity; Fair.Game. Read more>>
    PHP:

     
    Alice24, Mar 11, 2011 IP
  2. Alice24

    Alice24 Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    I found ;) i post here maybe helps
    function myTruncate($string, $limit, $break=".", $pad="...")
    {
      // return with no change if string is shorter than $limit
      if(strlen($string) <= $limit) return $string;
    
      // is $break present between $limit and the end of the string?
      if(false !== ($breakpoint = strpos($string, $break, $limit))) {
        if($breakpoint < strlen($string) - 1) {
          $string = substr($string, 0, $breakpoint) . $pad;
        }
      }
        
      return $string;
    }
    
    PHP:
    $description = "The World  Wide Web. When your average person on the street refers to
    the Internet, they're usually thinking of the World Wide Web. The Web is basically a
    series of documents shared with the world written in a coding language called Hyper Text
    Markup Language or HTML. When you see a web page, like this one, you downloaded a document
    from another computer which has been set up as a Web Server.";
    PHP:
    $shortdesc = myTruncate($description, 300);
      echo "<p>$shortdesc</p>";
    PHP:
    source http://www.the-art-of-web.com/php/truncate/
     
    Alice24, Mar 11, 2011 IP
  3. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Thanks, I was searching for function which looks on break string, . in this case.
    So it finds dot (".") in that limit and then truncates it to shorter string?
     
    G3n3s!s, Mar 11, 2011 IP
  4. Alice24

    Alice24 Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    it may be possible to be shorter, but you can use one to a number of limited caracthers (but this trim your word) You can find more examples on the source site i posted.
     
    Alice24, Mar 12, 2011 IP