문제

  <?php
  $utf8string = "سلامجهان";
    echo substr($utf8string,0,5);
?>
    //output سل�

How to fix substr() for utf-8 in php?

도움이 되었습니까?

해결책

<?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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top