搜索

首页  >  问答  >  正文

php - 使用substr 出现Use of undefined constant 0 - assumed ' 0'

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

substr("123456", 0, 2);

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

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

迷茫迷茫2798 天前1266

全部回复(2)我来回复

  • ringa_lee

    ringa_lee2017-06-10 09:49:52

    谢邀!

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

    回复
    0
  • typecho

    typecho2017-06-10 09:49:52

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

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

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

    Use of undefined constant 0

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

    回复
    0
  • 取消回复