PHP中读取(截取substr)字符串前N个字符或者从第几个字符开始取几个字符
<?php
$str = "123456789";
echo substr($str , 0 , 3);
echo substr($str , 3 , 3);
?>
<?php
$rest = substr("abcdef", -1);
$rest = substr("abcdef", -2);
$rest = substr("abcdef", -3, 1);
?>
<?php
$rest = substr("abcdef", 0, -1);
$rest = substr("abcdef", 2, -1);
$rest = substr("abcdef", 4, -4);
$rest = substr("abcdef", -3, -1);
?>
<?php
echo substr('abcdef', 1);
echo substr('abcdef', 1, 3);
echo substr('abcdef', 0, 4);
echo substr('abcdef', 0, 8);
echo substr('abcdef', -1, 1);
$string = 'abcdef';
echo $string[0];
echo $string[3];
echo $string[strlen($string)-1];
?>