復制代碼 代碼如下:
<?php
echo mb_substr('這樣一來我的字符串就不會有亂碼^_^', 0, 7, 'utf-8');
?>
復制代碼 代碼如下:
<?php
echo mb_strcut('這樣一來我的字符串就不會有亂碼^_^', 0, 7, 'utf-8');
?>
復制代碼 代碼如下:
mb_substr
mb_substr() returns the portion of str specified by the start and length parameters.
mb_substr() performs multi-byte safe substr() operation based on number of characters. Position is counted from the beginning of str. First character's position is 0. Second character position is 1, and so on.
mb_strcut
mb_strcut() returns the portion of str specified by the start and length parameters.
mb_strcut() performs equivalent operation as mb_substr() with different method. If start position is multi-byte character's second byte or larger, it starts from first byte of multi-byte character.
It subtracts string from str that is shorter than length AND character that is not part of multi-byte string or not being middle of shift sequence.
復制代碼 代碼如下:
<?php
$str = '我是一串比較長的中文-';
echo "mb_substr:" . mb_substr($str, 0, 6, 'utf-8');
echo "<br>";
echo "mb_strcut:" . mb_strcut($str, 0, 6, 'utf-8');
?>
新聞熱點
疑難解答