php怎么去除字符串前两位字符
- 建站笔记
- 2022-05-18
- 638
php去除字符串前两位字符的方法:1、使用substr()函数,语法“substr($str, 2)”;2、使用substr_replace()函数,语法“substr_replace($str, '', 0,2)”。
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php去除字符串前两位字符
1、使用substr()函数
substr() 函数可以从字符串的指定位置截取一定长度的字符,返回字符串的提取部分,如果失败则返回 FALSE,或者返回一个空字符串。
<?php $str = "hello,world"; $str2 = substr($str, 2); echo $str2; ?>
2、使用substr_replace()函数
substr_replace() 函数把字符串的一部分替换为另一个字符串。
<?php $str = "world"; $str2 = substr_replace($str, '', 0,2); echo $str2; ?>
本文由白琉璃于2022-05-18发表在白琉璃源码网,如有侵权或疑问,请联系我们,谢谢。
本文链接:https://www.bailiuli.com/t/2282.html
发表评论