1
Well I set up the following function to summarize a string in php.
function resumo($string,$chars) {
if (strlen($string) > $chars) {
while (substr($string, $chars, 1) <> ' ' && ($chars < strlen($string))) {
$chars++;
}
}
return substr($string, 0, $chars);
}
echo resumo("bla bla bla bla bla", 4);
Well the problem I am having is the following. I inform the amount of at most 4 letters and the function is returning me more letters.
And whenever Sting is summarized I want to add (...) three points. If I report a string that does not need to be summarized it is not necessary to add the three dots.
I don’t understand why you need that
while
, would not only return thesubstr()
?– rray
This makes things much easier https://answall.com/a/169912/3635
– Guilherme Nascimento