Mahmoud.Eskandari
Mahmoud.Eskandari

Reputation: 1478

php substr() for utf-8 characters without whitespace

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

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

Upvotes: 0

Views: 161

Answers (1)

Mahmoud.Eskandari
Mahmoud.Eskandari

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

Related Questions