- substr: documentation ( source)
- strrpos: documentation ( source)
<?php
function coupeChaine($text, $max) {
if (strlen($text) >= $max) {
$text = ereg_replace("<[^>]*>", "", $text);
$text = substr($text, 0, $max);
$positionEspace = strrpos($text, " ");
$text = substr($text, 0, $positionEspace)."...";
}
return $text;
}
echo coupeChaine('Ma chaine de <span>Test !!</span>', 15);
?>