php大括号的妙用,php截取最后一个字符
2009-10-30 文章来源:互联网 浏览次数:2144
分享文章
- // Get the first character of a string
- $str = 'This is a test.';
- $first = $str{0}; // $first = T;
- // Get the third character of a string
- $third = $str{2}; // $third = i;
- // Get the last character of a string.
- $str = 'This is still a test.';
- $last = $str{strlen($str)-1}; // $last = t;
- // Modify the last character of a string
- $str = 'Look at the sea';
- $str{strlen($str)-1} = 'e'; // $str = 'Look at the see';
- $a = "86-0754-88888888-";
- if ($a{strlen($a)-1} == "-")
- $a = substr($a,0,strlen($a)-1);
- echo $a;
其中 $a{strlen($a)-1}只在PHP5.0以上可用。

文章评论(查看全部)