couper les mots/phrases provenant d'une textarea trop longs ? - PHP - Programmation
Marsh Posté le 18-11-2002 à 11:37:35
Si ça peut t'aider, je viens de commencer ça: 
$chaine=====>le texte à traiter 
$nbr_cols===>la largeur de ton texte 
$max========>le nb max de caracteres 
 
<?php 
 Function formatage($chaine,$nbr_cols,$max) 
  { 
   $chaine = strip_tags(stripslashes(htmlspecialchars("$chaine" ))); 
   $chaine=Str_Replace("\n","",$chaine); 
   $taille = StrLen($chaine); 
   if($taille>$max) 
   { 
   die ("Votre message est trop long de ".($taille-4000)."caractères.<p align=center><input type='button' value='retour' onclick='history.go(-1)'></p>" ); 
   } 
 
 
   $tableau_mots=explode(" ",$chaine); 
    
   $chaine=$tableau_mots[0]; 
    
   $nbr_car=StrLen($tableau_mots[0]); 
    
   For ($i=1;$i<SizeOf($tableau_mots);$i++) 
    { 
     
     If (($nbr_car+StrLen($tableau_mots[$i])+1)>=$nbr_cols) 
      { 
       $chaine.="<BR>".$tableau_mots[$i]; 
       
       $nbr_car=StrLen($tableau_mots[$i]); 
        
      } 
     Else 
      { 
       $chaine.=" ".$tableau_mots[$i]; 
        
       $nbr_car=$nbr_car+StrLen($tableau_mots[$i])+1; 
        
      } 
    } 
   $chaine=nl2br($chaine); 
   Return $chaine; 
  } 
 
?> 
 
Marsh Posté le 18-11-2002 à 16:33:10
mwai, c un peu trop complexe et lourd ca enfin merci kan meme
Marsh Posté le 16-11-2002 à 15:02:04
slt,
 
 
 
 
 
 
comment faire ?
ya bien la fonction wordwrap(), mais j'arrive pas a l'utiliser correctement: ca coupe le bb code et le code des smilies
g aussi essaye avec l'attribut wrap="physical", mais ca a pas l'r de fonctionner
alors help please !!!