TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   how to shorten a string outputed? (http://www.talkphp.com/absolute-beginners/3961-how-shorten-string-outputed.html)

sarmenhb 02-11-2009 06:22 PM

how to shorten a string outputed?
 
if i have an uknown length of a string being outputted how can i limit it to only 16 characters to be outputted?

Salathe 02-11-2009 06:36 PM

How about:
PHP Code:

$short substr($long016); 


Wildhoney 02-11-2009 06:45 PM

That's exactly how you do it. I'll share my function I use with you:

php Code:
public static function shorten($szString, $iLength, $szPrepend = '...')
{
    $iChopLength = strlen($szString) - $iLength;

    if ($iChopLength > 0)
    {
        $szString = substr($szString, 0, $iLength - strlen($szPrepend)) . $szPrepend;
    }

    return $szString;
}


All times are GMT. The time now is 11:26 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0