当前位置:网站首页>php如何去除首位数字
php如何去除首位数字
2022-04-21 18:11:00 【亿速云】
php如何去除首位数字
这篇文章主要讲解了“php如何去除首位数字”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“php如何去除首位数字”吧!
去除方法:1、使用substr_replace()函数将首位数字替换为空字符串即可,语法“substr_replace($num,"",0,1)”;2、用substr截取从第二位数字开始的全部字符即可,语法“substr($num,1)”。

本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
在php中,给你一大串的数值,例“123456789”,怎么去掉其首位数字“1”,即返回“23456789”尼?
其实,PHP提供了多种解决方法,下面本篇文章给大家介绍两种方法。
方法1:使用substr_replace()函数
substr_replace() 函数把字符串的一部分替换为另一个字符串。
substr_replace(string,replacement,start,length)
当替换值replacement参数设置为空字符串''时,可实现删除子串的功能。
而想要去除第一位的数字字符,需要将替换位置start设置为0,替换个数lengths设置为1即可。
实现示例:
<?phpheader('content-type:text/html;charset=utf-8'); $num=123456789;echo substr_replace($num,"",0,1);?>

方法2:使用substr函数
substr() 函数可以从字符串的指定位置截取一定长度的字符。
substr(string, start , length)
当截取位置start设置为1,截取长度length省略时,可从字符串索引1处(第二个字符处)开始截取剩余的全部字符,即可实现删除第一位的数字字符。
实现示例:
<?phpheader('content-type:text/html;charset=utf-8'); $num=123456789;echo substr($num,1);?>

感谢各位的阅读,以上就是“php如何去除首位数字”的内容了,经过本文的学习后,相信大家对php如何去除首位数字这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
版权声明
本文为[亿速云]所创,转载请带上原文链接,感谢
https://www.yisu.com/zixun/694142.html
边栏推荐
- 还剩下载次数,可留链接+邮箱
- Summary of mongodb user permissions
- Appreciation of single chip microcomputer DIY works, beginners come in to worship
- TCP/IP协议
- [AI and food] a review paper on the latest "dietary assessment based on visual analysis" by the Institute of computing, Chinese Academy of industry and Commerce
- After reading this tutorial, you will have your own satellite (DIY full explanation)
- Logstash ~ how logstash works
- 不同研发协作模式在云效中的应用
- 华为云GaussDB(for Influx)揭密第六期——数据分级存储
- Intermediary model
猜你喜欢
随机推荐
Detailed explanation of kubernetes (III) -- kubernetes cluster components
SQL command delete (I)
干货 | 谁懂这篇文,玩游戏还会卡顿?
靶机渗透练习77-DC9
WPF RichTextBox赋值与取值
Reptile case 01
[untitled]
【论文精读】Stable Linear Structures and Seam Measurements for Parallax Image Stitching
Headline we media operation secret script. If you stick to it, you can beat 90% of the people
Do we media sidelines really earn tens of thousands a month? This article is shared without privacy
单片机能做什么,你有什么有单片机或开源硬件做的有意思的作品吗
干货 | 读懂 Appium 日志,让测试效率翻倍!
Integer面试解析、equals与==的区别
How can the manufacturing industry save itself under the crisis of insufficient personnel and broken supply chain?
【Redis】 使用Redis优化省份展示数据不显示
Porting openharmony and adding WiFi driver
C语言进阶第48式:函数设计原则
封装的JDBC工具
不同研发协作模式在云效中的应用
一个通用的CommonDialog









