SolutionCottage.com
Posted  02 Apr 2010 - 15:39:41

Category: PHP


substr turns swedish characters to questionmarks

Issue:
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.

Solution:
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




0 comments:








© SolutionCottage 2008-2011 7/26/2017 1:42:16 AM