加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php 截取utf-8格式的字符串实例代码

发布时间:2020-12-12 21:49:05 所属栏目:PHP教程 来源:网络整理
导读:php 截取utf-8格式的字符串 php中,我们经常需要截取字符串。英文字符占用一个字节,中文字符占用两个字节,但中文字符占用两个字节是相对于GBK编码而言但是在时下国际流行的UTF8编码中,一个中文字符占用3个字节。本文章向大家介绍一个php 截取utf-8格式字

php 截取utf-8格式的字符串

php中,我们经常需要截取字符串。英文字符占用一个字节,中文字符占用两个字节,但中文字符占用两个字节是相对于GBK编码而言但是在时下国际流行的UTF8编码中,一个中文字符占用3个字节。本文章向大家介绍一个php 截取utf-8格式字符串的函数。

举例说明:

0)); $i ++) { if ($number = strpos ( str_pad ( decbin ( ord ( substr ( $string,$i,1 ) ) ),8,'0',STR_PAD_LEFT ),'0' )) { if ($length < 1.0) { break; } $result .= substr ( $string,$number ); $length -= 1.0; $i += $number - 1; } else { $result .= substr ( $string,1 ); $length -= 0.5; } } $result = htmlspecialchars ( $result,'UTF-8' ); if ($i < $strlen) { $result .= $etc; } return $result; }

如果需要截取utf-8格式的字符串,直接调用这个函数即可。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读