FANDOM


If you run a community driven website and cannot control the text submitted by users, this function may be of use. Sometimes, submitted text is just too long to fit in a specific area, but too important to not exist at all. This function will allow you to quickly truncate the string, and add a trailing string to the truncated one.

For example:Edit

Original: "The quick brown fox jumps over the lazy dog."

Truncated: "The quick brown fox jumps over..."

The Code:Edit

function truncate($string, $length, $trailing) {
if(strlen($string) > $length) return substr($string,0,$length).$trailing;
return $string;
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.