This question already has an answer here:
I have a telephone verification system in place. This allows the customer to enter a phone number. However, how can I remove all 0
's from the start of the string?
For example I could use substr
to remove one or two 0
's but what if the customer enters ten or twelve of them?
i.e The customer could enter one of the following numbers:
How can I remove all 0
's from the start only, not from the rest of the string?
</div>
also you can use regexp
$result = preg_replace('/^0*/', '', $number);
Really? Leading 0s are dialling prefixes -- if you take them off, the phone number is not the same & may (likely) be undiallable. You make also encounter plus '+' which is an international dialling prefix, and is (meant to be) standard from location to location.
If you really want to remove leading '0's, then use ltrim.
$trimmed = ltrim( $phone, '0');