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条)

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证