©
本文档使用
php中文网手册 发布
(PHP 5, PHP 7)
iconv_substr — 截取字符串的部分
$str
, int $offset
[, int $length = iconv_strlen($str, $charset)
[, string $charset = ini_get("iconv.internal_encoding")
]] )
根据 offset 和 length 参数指定 str 截取的部分。
str 原始字符串。
offset
如果 offset 是非负数, iconv_substr() 从 str 开头第 offset 个字符开始截出部分,从 0 开始计数。
如果 offset 是负数, iconv_substr() 从 str 末尾向前 offset 个字符开始截取。
length
如果指定了 length 并且是正数,返回的值从 offset 截取部分,最多包含 length 个字符(取决于 string 的长度)。
如果传入了负数的 length,
iconv_substr() 将从第 offset 个字符到离末尾 length 个字符截出 str 的部分。
如果 offset 也是负数,则开始位置计算规则的解释见以上。
charset
如果省略了参数 charset,string 的编码被认定为 iconv.internal_encoding。
注意,offset 和 length 参数总是被认为字符表现的偏移,基于 charset 检测到的字符集进行统计计算,而相对应的 substr() 则是基于字节的位移来计算。
返回 offset 和 length 参数指定的 str 的部分。
如果 str 比 offset 字符数更短,将会返回 FALSE 。
[#1] doru87 at gmail dot com [2010-01-21 05:29:20]
just fyi, iconv_substr() unknown error (0) has been resolved in PHP 5.2
you can also try mb_substr() or just substr() when dealing with this issue. Unfortunately there is no way to fix it in versions prior to 5.2.
Regards,
Teodor Sandu
[#2] qbolec at terra dot es [2007-05-25 02:07:50]
<?php=
iconv_substr("A",0,1);
?>
generates folowing error:
Notice: iconv_substr() [function.iconv-substr]: Unknown error (0) in [...]
while,
<?php= iconv_substr("AB",0,1) ?>
and
<?php= iconv_substr("AB",0,2) ?>
work as expected.