Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不带空格的utf-8字符的php substr() //产出�_Php_Substring_Substr - Fatal编程技术网

不带空格的utf-8字符的php substr() //产出�

不带空格的utf-8字符的php substr() //产出�,php,substring,substr,Php,Substring,Substr,如何在php中修复utf-8的substr()?可以看出,您正在寻找。第三个参数是长度,而不是结束位置。 <?php $utf8string = "سلامجهان"; echo substr($utf8string,0,5); ?> //output سل� <?php $utf8string = "سلامجهان"; echo mb_substr($utf8string,0,5,'UTF-8');

如何在php中修复utf-8的substr()?

可以看出,您正在寻找。第三个参数是长度,而不是结束位置。
  <?php
  $utf8string = "سلامجهان";
    echo substr($utf8string,0,5);
?>
    //output سل�
<?php
        $utf8string = "سلامجهان";
        echo mb_substr($utf8string,0,5,'UTF-8');
        //output سلامج
?>
//sample  mb_substr($YourString,first char,length of output char,charset name);