Rasher's Toolbox

Back

cut

string cut(string string, int width [, string padding]) -- Truncate a string.

Description

Cut will return a string that is no longer than width characters long. The string will be suffixed with '...' or padding if it was cut.

Example

<?php
  
echo cut('This is a long string containing 47 characters'15);
?>

This will output:

This is a lo...

Source

Published under the terms of the BSD License

<?php
function cut($string$width$padding "...") {
    return (
strlen($string) > $width substr($string0$width-strlen($padding)).$padding $string);
}
?>

Last updated: Sat Jun 14 20:02:45 CEST 2008

Valid XHTML 1.0! Valid HTML 3.2!