How to remove all leading zeroes in a string

前端 未结 10 1181
感情败类
感情败类 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条回答
  •  萌比男神i
    2020-12-02 07:59

    Assuming you want a run-on of three or more zeros to be removed and your example is one string:

        $test_str ="0002030050400000234892839000239074";
        $fixed_str = preg_replace('/000+/','',$test_str);
    

    You can make the regex pattern fit what you need if my assumptions are off.

    This help?

提交回复
热议问题