Truncate String





8
Date Submitted Sun. Oct. 9th, 2005 8:32 PM
Revision 1 of 1
Coder mattrmiller
Tags PHP | String | Truncate
Comments 0 comments
Truncate String
<?php
        function TruncateString($strString, $nLength = 15, $strTrailing = "...")
        {
                // Take off chars for the trailing
                $nLength -= strlen($strTrailing);
                if (strlen($strString) > $nLength)
                {
                        // -- String exceeded length, truncate and add trailing dots
                        return substr($strString, 0, $nLength) . $strTrailing;
                }
                else
                {
                        // -- String was already short enough, return the string
                        return $strString;
                }
        }
?>

Matthew R. Miller

www.bluecreststudios.com
=================
Matthew R. Miller

http://bluecreststudios.com
http://www.codeandcoffee.com

Comments

There are currently no comments for this snippet.

Voting