Reputation:
Is there a simple way to remove a leading zero (as in 01 becoming 1)?
Upvotes: 2
Views: 3643
Reputation: 75794
Regex replace /^0*/
with '' for a string return solution
The exact code will be something like this
<?php
$string_number = '000304';
echo preg_replace('/^0*/', '', $string_number);
?>
Upvotes: 0
Reputation: 8855
if you use the trim functions, you might mistakenly remove some other character, like by triming "12" your will have "2". use the intval() function. this function will convert your string (which could start by a leading zero or not) to an integer value. intval("02") will be 2 and intval ("32") wll be 32.
Upvotes: 4