Ver Mensaje Individual
  #6 (permalink)  
Antiguo 02/07/2007, 12:08
Avatar de david_M_G
david_M_G
 
Fecha de Ingreso: febrero-2005
Mensajes: 938
Antigüedad: 19 años, 2 meses
Puntos: 20
Re: recortar texto

Puedes utilizar esta función:

Código PHP:
function cut_string($string$charlimit)
{
   if(
substr($string,$charlimit-1,1) != ' ')
   {
       
$string substr($string,'0',$charlimit);
       
$array explode(' ',$string);
       
array_pop($array);
       
$new_string implode(' ',$array);

       return 
$new_string;
   }
   else
   {  
       return 
substr($string,'0',$charlimit-1);
   }

Y si quieres recortar, pones el nombre de la variable y tras la coma la longitud máxima aceptada:

Código PHP:
echo cut_string($texto20);