Reputation: 1478
<?php
$utf8string = "سلامجهان";
echo substr($utf8string,0,5);
?>
//output سل�
How to fix substr() for utf-8 in php?
Upvotes: 0
Views: 161
Reputation: 1478
<?php
$utf8string = "سلامجهان";
echo mb_substr($utf8string,0,5,'UTF-8');
//output سلامج
?>
Use mb_substr and set utf-8 for it!
//sample mb_substr($YourString,first char,length of output char,charset name);
Upvotes: 1