mb_strimwidth

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

mb_strimwidth获取按指定宽度截断的字符串

说明

mb_strimwidth ( string $str , int $start , int $width [, string $trimmarker = "" [, string $encoding = mb_internal_encoding() ]] ) : string

width字符串 str 截短。

参数

str

要截短的 string

start

开始位置的偏移。从这些字符数开始的截取字符串。(默认是 0 个字符) 如果 start 是负数,就是字符串结尾处的字符数。

width

所需修剪的宽度。负数的宽度是从字符串结尾处统计的。

trimmarker

当字符串被截短的时候,将此字符串添加到截短后的末尾。

encoding

encoding 参数为字符编码。如果省略,则使用内部字符编码。

返回值

截短后的 string。 如果设置了 trimmarker,还将结尾处的字符替换为 trimmarker ,并符合 width 的宽度。

更新日志

版本 说明
7.1.0 支持负数的 startwidth

范例

Example #1 mb_strimwidth() 例子

<?php
echo mb_strimwidth("Hello World"010"...");
// 输出 Hello W...
?>

参见

相关文章
php 多字节字符串 函数 检查字符串在指定的编码里是否有效php 多字节字符串 函数 解码 mime 头字段中的字符串php 多字节字符串 函数 根据 html 数字字符串解码成字符php 多字节字符串 函数 检测字符的编码php 多字节字符串 函数 multibyte regular expression match for predefined multibyte stringphp 多字节字符串 函数 regular expression match with multibyte supportphp 多字节字符串 函数 replace regular expression with multibyte support ignoring casephp 多字节字符串 函数 descriptionphp 多字节字符串 函数 发送编码过的邮件php 多字节字符串 函数 使用正则表达式分割多字节字符串php 多字节字符串 函数 获取按指定宽度截断的字符串php 多字节字符串 函数 查找指定字符在另一个字符串中最后一次的出现php 多字节字符串 函数 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现php 多字节字符串 函数 返回字符串的宽度php 多字节字符串 函数 设置/获取替代字符php 多字节字符串 函数 统计字符串出现的次数php 字符串 函数 计算指定字符串在目标字符串中最后一次出现的位置(不区分大小写)php 字符串 函数 计算指定字符串在目标字符串中最后一次出现的位置php xml 解析器函数 将用 utf 8 方式编码的 iso 8859 1 字符串转换成单字节的 iso 8859 1 字符串。php 字符串 函数 打断字符串为指定数量的字串
关注编程学问公众号