Trim any zeros at the beginning of a string using PHP

后端 未结 6 2090
庸人自扰
庸人自扰 2021-02-13 17:59

Users will be filling a field in with numbers relating to their account. Unfortunately, some users will have zeroes prefixed to the beginning of the number to make up a six dig

6条回答
  •  轮回少年
    2021-02-13 18:26

    You can drop the leading zeros by converting from a string to a number and back again. For example:

    $str = '000006767';
    echo ''.+$str; // echo "6767"
    

提交回复
热议问题