<?php
$utf8string = "سلامجهان";
echo substr($utf8string,0,5);
?>
//output سل�
如何修复php中utf-8的substr()?
答案 0 :(得分:2)
<?php
$utf8string = "سلامجهان";
echo mb_substr($utf8string,0,5,'UTF-8');
//output سلامج
?>
使用mb_substr并为其设置utf-8!
//sample mb_substr($YourString,first char,length of output char,charset name);