This code will truncate given text to a certain length, adding “…” where it’s been truncated. For example:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque ac urna a erat pharetra placerat. Sed at tortor id lacus pellentesque malesuada. Suspendisse vitae dui vel velit tincidunt aliquet. Cras condimentum lobortis leo. Integer semper. Nunc semper felis a neque malesuada posuere. Quisque convallis dolor sed erat. Mauris tellus. Nulla vestibulum diam sed felis. Aenean mi orci, fringilla at, vulputate dapibus, cursus ut, sem.

Would be turned into:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque ac…

Shorten text
 $shortened_text_num ) {
        $shortened_text .= "... ";
    }
    return strip_tags($shortened_text);

}
?>

Advertisement

Themeforest
ssd-virtual-servers-banner-468x60
Previous post

Google Style Page Numbering (with x per page and y page numbers displayed)

Next post

Displaying file sizes in human readable format

snipe

snipe

I’m a tech geek/dev/infosec-nerd/scuba diver/blacksmith/sword-fighter/crime fighter/ENTP/warcrafter/activist. I'm the CTO at Mass Mosaic and the CEO of Grokability, Inc. in San Diego, CA. Tweet at me @snipeyhead or read more...