How to remove all leading zeroes in a string

前端 未结 10 1202
感情败类
感情败类 2020-12-02 07:16

If I have a string

00020300504
00000234892839
000239074

how can I get rid of the leading zeroes so that I will only have this



        
10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 07:53

    Ajay Kumar offers the simplest echo +$numString; I use these:

    echo round($val = "0005");
    echo $val = 0005;
        //both output 5
    echo round($val = 00000648370000075845);
    echo round($val = "00000648370000075845");
        //output 648370000075845, no need to care about the other zeroes in the number
        //like with regex or comparative functions. Works w/wo single/double quotes
    

    Actually any math function will take the number from the "string" and treat it like so. It's much simpler than any regex or comparative functions. I saw that in php.net, don't remember where.

提交回复
热议问题