Tronquer une chaîne de caractère trop longue.
Tronque une chaîne de caractère trop longue.
|
|
Code Source
Fonctions du code
Commentaires
<?php
$chaine = 'Le texte que vous vouler tronquer !';
$lg_max = 20; //nombre de caractère autorisé
$fin = ' ...'; //chaîne de fin
if (strlen($chaine)>$lg_max)
{
$chaine=substr($chaine, 0, $lg_max-strlen($fin)).$fin;
}
echo $chaine;
?>
excelente source!
merci.
merci.
Encore plus conci...
function strCut($string, $max = 60, $end = '...') {
if (strlen($string) > $max) {
$string = substr($string, 0, $max - strlen($end)).$end;
}
return $string;
}
function strCut($string, $max = 60, $end = '...') {
if (strlen($string) > $max) {
$string = substr($string, 0, $max - strlen($end)).$end;
}
return $string;
}
Ajouter un commentaire
Librairie PHP
Connexion
Chaînes
PHP
- Affichage (5)
- Applications (9)
- Chaînes (71)
- Classes (29)
- Constantes (4)
- Cookies (3)
- Date-Heure (40)
- Email (14)
- Fichiers - Réps (45)
- Fonctions (23)
- Formulaires (18)
- GD-Graphiques (11)
- Google (13)
- HTML (7)
- Images (21)
- Inclassable (28)
- Maths (24)
- MySQL (23)
- Navigateurs (6)
- Recherches (6)
- Regex (13)
- Reseau (2)
- Sécurité (25)
- Sessions (13)
- Statistiques (5)
- Système (18)
- Tableaux (21)
- Tag-cloud (3)
- Templates (3)
- Twitter (5)
- URL (22)
- Variables (8)
- Vidéos (2)
- Windows (1)
- XML (2)





















