Home  >  Q&A  >  body text

php - Use of undefined constant 0 - assumed ' 0' when using substr

In php version 5.6, use the substr function to intercept strings. code show as below

substr("123456", 0, 2);

AppearUse of undefined constant 0 - assumed ' 0'

The online solution is to modify error_reporting in php.ini to turn off notice. But what is this essential question? ? If you don't close this notice configuration, how to solve it? ?

迷茫迷茫2582 days ago1062

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-06-10 09:49:52

    Thanks for the invitation!

    It’s not a function problem, but that you used the undefined constant 0. You can take a look at your code again. Is the 0 in your context a full-width space?

    Reply
    0
  • typecho

    typecho2017-06-10 09:49:52

    If I read it correctly, this Use of undefined constant 0 - assumed ' 0'.

    0 There is a space in front of it. If it is just a space (u20), there should be no error.

    I guess you used full-width spaces, causing '0' to become a variable. But in PHP, variables need to be defined with $, so this '0' is programmed as a constant.

    Use of undefined constant 0

    Translation: Undefined constant used.

    Reply
    0
  • CancelReply