I'm trying to properly understand strlen()
in PHP to make a application where text is shortened and finished with a ...
My code:
$prize_text = "Learn how to eat pizza TODAY";
if (strlen($prize_text) > 24) {
$prize_text = substr($prize_text, 0, 21) . '...';
}
$prize_text = "Watch Good Day Sunshine Today!";
$prize_text = "abcdefghijklmnopqrstuvwxyz";
Why is everything not matching up? I want one uniform standard of shortening the text and then appending three dots. What is wrong with my code?
Wrong tool for the job. You want CSS instead to avoid the breaking problem you're having.
#element {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
Advantages