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;
}
}
?>
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;
}
}
?>





There are currently no comments for this snippet.