douza19870617 2014-06-30 08:25
浏览 40
已采纳

PHP子字符串不适用于整数[重复]

This question already has an answer here:

I am trying to extract part of a number using sustr() but the following is not working:

$num = 012014;

echo substr($num, 0,2);

returns 51

BUT

$num = '012014';

echo substr($num, 0,2);

returns 01

I want it to return 01 can someone help me

</div>
  • 写回答

4条回答 默认 最新

  • dongluo6343 2014-06-30 08:31
    关注

    Is is not a normal number, when it's prepended with a zero (0). Then it's an octal number

    If you treat $num as a string, it'll work.

    $num = '012014';
    echo substr($num, 0,2);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥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的方法去调试网页