Posted  02 Apr 2010 - 15:39:41

Category: PHP

substr turns swedish characters to questionmarks

When you try to use substr to get a portion of a text you might sometimes notice a questionmark (at least in Firefox) instead of some multibyte character. In the swedish language examples of these are å, ä and ö. What you need to know is that substr is not multibyte safe and will cut them in half basically.

You need to use the multibyte safe function mb_substr. Don't worry, it's easy:

$aStr = "åäö";
$portion = mb_substr($aStr, 0, 1, 'UTF-8');
echo $portion;

Marked as helpful by 2 users


© SolutionCottage 2008-2011 9/24/2017 1:12:02 PM