function ResumeTexto($text, $maxChars = 20, $splitter = '...'){
$theReturn = $text;
$lastSpace = false;
if (strlen($text) > $maxChars) { $theReturn = substr($text, 0, $maxChars - 1);
if (in_array(substr($text, $maxChars - 1, 1), array(' ', '.', '!', '?'))) {
$theReturn .= substr($text, $maxChars, 1);
} else {
$theReturn = substr($theReturn, 0, $maxChars - strlen($splitter));
$lastSpace = strrpos($theReturn, ' ');
if ($lastSpace !== false) { $theReturn = substr($theReturn, 0, $lastSpace); }
if (in_array(substr($theReturn, -1, 1), array(','))) { $theReturn = substr($theReturn, 0, -1); }
$theReturn .= $splitter;
}
}
return $theReturn;
}
martes, 24 de julio de 2012
Resume Texto
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario