Created
March 15, 2012 18:59
-
-
Save oscar-reales-interactiv4/2046059 to your computer and use it in GitHub Desktop.
Truncate long text function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Esta funcion devuelve una cadena pasada como parametro | |
* truncada a un maximo de caracteres segun parametro | |
* @param string $string | |
* @param int $maxLength | |
* @return string | |
*/ | |
public function truncateString($string, $maxLength) | |
{ | |
if(mb_strlen($string) > $maxLength) | |
{ | |
$maxLength = $maxLength - 3; //para los puntos suspensivos | |
return mb_substr($string, 0, $maxLength) . "..."; | |
} else { | |
return $string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment