函数名:iconv_substr()
适用版本:PHP 4 >= 4.0.6, PHP 5, PHP 7
函数描述:iconv_substr() 函数用于返回一个字符串的子串,其中包含指定的字符数和指定的字符编码。
语法:string iconv_substr ( string $str , int $start [, int $length = iconv_strlen($str, $charset) [, string $charset = ini_get("iconv.internal_encoding") ]] )
参数:
返回值:返回截取的子串,如果发生错误则返回 FALSE。
示例:
$str = "Hello, world!";
$sub = iconv_substr($str, 7, 5, "UTF-8");
echo $sub; // 输出 "world"
在上面的示例中,我们使用 iconv_substr() 函数从字符串 "Hello, world!" 中截取了从位置 7 开始的 5 个字符,并指定了字符编码为 "UTF-8"。最后输出的结果是 "world"。