I'm building a website about health. And I need to display some symptoms along with their data in a table. However, the names of some symptoms are too long, wich causes a layout issue. So, I found a way to shorten their names with PHP, as you can see below:
<?=strlen($a)>45 ? stripslashes(substr($a, 0, 45)."...") : stripslashes($a)?>
It works fine. The only problem is when the string is cut in the middle of an HTML Entity, which causes the browser to display a diamond with a question mark instead (http://prntscr.com/dzqyps).
Example:
Original string:
long string with more than x characters ends já
Truncated string:
long string with more than x characters ends j&aa...
String as displayed in the browser:
long string with more than x characters ends j?...
How can I solve this issue?