if (strlen($string) > $size) {
) so that it does not happen if the array has "..." at the end of the sentence
$prod->setNome(Utility::limitaString($prod->getNome(), 30));
public static function limitaString ($string, $size = 50) {
if (strlen($string) > $size) {
$string = substr($string, 0, $size);
for ($i=$size; $i>=0; $i--) {
$limiters = array(" ", "\n", "\t");
if (in_array($string[$i], $limiters)) {
if ($string[$i-1] == "\r")
$i = $i-1;
$string = substr($string, 0, $i);
$string .= "...";
return $string;
}
}
$string .= "...";
}
return $string;
}
This above function is done to reduce the sentence to 30 characters and adds "..." at the end of the sentence. but I need this condition for some already abbreviated sentences that I do not want by the method.
As would be the condition for array with at the end "...".