PX : code

Cutting Text and Adding "..." by Allan Denot
Download this code


<?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($texto0$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.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.