Frage

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

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

War es hilfreich?

Lösung

<?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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top