Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Oakham England

    [PHP] Shortening Text from DB


    I have a database that runs the news for a website, this includes HTML such as <b>, <i>, <u>

    However I need to make the text shorter to 255 letters and add ... but take of ending of words.

    But I cant get my script to do it!

    Here is that I have....

    PHP Code:

    $desc trim(substr($desc0256));
    $len strlen($desc) -1;
    $x strpos($desc'<'); 
    $x !== false && $x $len$len $x;
    $desc[$len] != ".")
    $len 20 && ord($desc[$len]) != 32$len--;
    $desc trim(substr($desc0$len)) . "...";

    Please help asap
    Streama - Your WordPress Friend

  2. #2
    Join Date
    Aug 2008
    Cyprus, EU
    A function like the one below should do the job, but if you dont strip the tags, you might get unexpected results because of improperly closed/open tags.
    PHP Code:
    function short_txt($str,$char){
    $str strip_tags($str);
    $str ereg_replace("[\r\t\n\"]"," ",$str);
    $str =substr($str0$char);
    $str  substr($str,0,strrpos($str ," "));

    $desc $row["post_content"];

Similar Threads

  1. New URL Shortening Service
    By WO-Jacob in forum Web Site Reviews
    Replies: 4
    Last Post: 05-31-2009, 08:40 PM
  2. [Looking For] PHP Developer - URL Shortening Script
    By jordanriane in forum Software & Scripts Requests
    Replies: 1
    Last Post: 05-08-2009, 10:58 AM
  3. Review my URL Shortening Service
    By LH-Danny in forum Web Site Reviews
    Replies: 0
    Last Post: 04-08-2009, 12:20 PM
  4. URL Shortening
    By kimchris in forum Web Site Reviews
    Replies: 1
    Last Post: 08-20-2008, 12:31 PM
  5. For Sale: URL shortening site
    By abluegrape in forum Other Offers & Requests
    Replies: 7
    Last Post: 01-17-2006, 06:46 PM

Posting Permissions

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