Using PHP's substr() with special characters at the end results in question marks

If your string has multibyte encoding (like UTF-8) does, you should use mb_substr to avoid problems like this:

$introtext=mb_substr($introtext,0,200);

In case someone tried the previous answers, and it still didn't work:

Try to add a Unicode name in mb_substr like:

$introtext = mb_substr($introtext, 0, 200, 'utf-8');

That is because substr does not work with multibyte characters. substr will probably cut a multibyte character "in half". You should instead use mb_substr. Also make sure that your file is saved in UTF-8.

$introtext = mb_substr($introtext, 0, 200);

Tags:

Php

Joomla

Substr