0
how can I put a condition on if(if (strlen($string) > $size) {
) so it doesn’t 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 function above is done to reduce the sentence to 30 characters and add "..." at the end of the sentence. but I need this condition for some already abbreviated sentence that I don’t want by the method.
how would be condition for array with at the end "...".