Using PHP's substr() with special characters at the end results in question marks
Asked 07 September, 2021
Viewed 2.5K times
  • 51
Votes

When I use the substr() function in PHP, I get an question mark (a square with a question mark - depending on the browser) at the end of the string when this last character was a special one, like ë or ö, etc...

$introtext = html_entity_decode($item->description, ENT_QUOTES, "UTF-8");
$introtext = substr($introtext, 0, 200);

How can I escape this?

4 Answer