Tuesday, March 31, 2015

Getting a substring of UTF-8 characters - PHP Snippet

Getting a substring of UTF-8 characters - PHP Snippet

You can return a part of UTF-8 string using mb_string function

$utf8string = "cakeæøå";

echo substr($utf8string,0,5);
// output cake#

echo mb_substr($utf8string,0,5,'UTF-8');
//output cakeæ

Disqus Comments