If you want to remove all leading zeroes in a string in PHP? Use $str = ltrim($str, '0');
.
1 2 3 4 5 6 7 | <?php $x = '000547023.24'; $str1 = ltrim($x, '0'); echo $str1."\n"; ?> |
preg_replace()
function1 2 3 4 5 | <?php $number = '00000004523423400023402340240'; $withoutLeadingZeroes = preg_replace('/^0+/', $number) echo $withoutLeadingZeroes; ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.