php - 使用substr 出现Use of undefined constant 0 - assumed ' 0'
迷茫
迷茫 2017-06-10 09:47:52
0
2
1297

php版本5.6中使用substr函数 进行字符串截取。代码如下

substr("123456", 0, 2);

出现Use of undefined constant 0 - assumed ' 0'

网上解决方案是修改 php.ini 中error_reportingnotice关闭。但是这个本质问题是什么?? 如果不关闭这个notice配置,怎么解决??

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(2)
左手右手慢动作

谢邀!

不是函数的问题,而是你使用了未定义的常量0,你可以再去看看你的代码。你的上下文中的0是不是加了个全角的空格。

typecho

如果我没有看错的话,这个 Use of undefined constant 0 - assumed ' 0'.

0 前面有一个空格,如果单纯是空格(u20)的话,应该没有错误。

我猜测你使用了全角空格,导致 ' 0' 变当作了变量。但是在 PHP 中,变量需要加 $ 来定义,所以这个 ' 0' 就编程了常量。

Use of undefined constant 0

翻译:使用了未定义的常量。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板