How to remove all leading zeroes in a string

前端 未结 10 1121
感情败类
感情败类 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 08:01

    Don't know why people are using so complex methods to achieve such a simple thing! And regex? Wow!

    Here you go, the easiest and simplest way (as explained here: https://nabtron.com/kiss-code/ ):

    $a = '000000000000001';
    $a += 0;
    
    echo $a; // will output 1
    

提交回复
热议问题