【问题标题】:php substr() for utf-8 characters without whitespacephp substr() 用于不带空格的 utf-8 字符
【发布时间】:2014-02-12 08:58:29
【问题描述】:
  <?php
  $utf8string = "سلامجهان";
    echo substr($utf8string,0,5);
?>
    //output سل�

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

【问题讨论】:

标签: php substring substr


【解决方案1】:
<?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);

【讨论】:

  • 第三个参数是长度,不是结束位置。
猜你喜欢
  • 1970-01-01
  • 2011-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-23
  • 2013-02-09
相关资源
最近更新 更多