douna1941 2015-02-12 16:20
浏览 81
已采纳

php is_numeric零填充字符串(0000018)

I have tested is_numeric on zero filled ints such 0000018 and it return true. The documentation says:

"Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal (e.g. 0xf4c3b00c), Binary (e.g. 0b10100111001), Octal (e.g. 0777) notation is allowed too but only without sign, decimal and exponential part."

Would this fall under the any number of digits part?

  • 写回答

2条回答 默认 最新

  • duanji5569 2015-02-12 16:30
    关注

    Both cases (string and the (invalid)octal number) will return true:

    var_dump( is_numeric("0000018") );  //bool(true)
    var_dump( is_numeric(0000018) );    //bool(true)
    

    In the first case it's just a numeric string.

    A quote from the manual (is_numeric()):

    Returns TRUE if var is a number or a numeric string, FALSE otherwise.

    In the second case it is a octal number, just a invalid one, so this will happen (From the manual Integer):

    Warning: If an invalid digit is given in an octal integer (i.e. 8 or 9), the rest of the number is ignored.

    Means in this case:

    0000018 -> 000001 -> 1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染