Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Character Chopper (See related posts)

// This function will limit by number of characters.
// usage: $var = char_chop($str(string), $string_length limit of chars, default: 30));


function char_chop($str, $string_length = 30) {
        $s = strlen($str);
        if($s > $string_length){
                $str = substr(0, $string_length, $str);
                $str .= '...';
        }
        return($str);
}


You need to create an account or log in to post comments to this site.


Related Posts