| px | top | add code | search | signup | login | help |
<?php
// written by Allan Denot
// spike@consultant.com
// visit my site at:
// www.console.com.br
function cuttext($texto,$tamanho) {
$texto = htmlspecialchars($texto);
if (strlen($texto) > $tamanho) {
$texto = substr($texto, 0, $tamanho);
$texto .= " ...";
}
return $texto;
}
// Example -----------------
$texto = "Rio de Janeiro is the most beautiful city of the world!";
echo cuttext($texto,37); // it will cut the text at char 37 and add ...
/* it returns: "Rio de Janeiro is the most beautiful ..." */
// -------------------------
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.