How to remove all leading zeroes in a string

前端 未结 10 1199
感情败类
感情败类 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:46

    I don't think preg_replace is the answer.. old thread but just happen to looking for this today. ltrim and (int) casting is the winner.

    "; 
     echo $fixed_str1 . " Fix1";
     echo "
    "; echo $fixed_str2 . " Fix2"; echo "
    "; echo $fixed_str3 . " Fix3"; echo "
    "; echo $actualInt . " Actual integer in string"; //output 0000001123000 Origina 1123 Fix1 1123000 Fix2 1123000 Fix3 1123000 Actual integer in tring

提交回复
热议问题