Reputation: 138
here is field name "phone number". i want to store data in the database table without leading zero when a user can input phone number like '01323442234' or '1323442234'.
input = '01323442234' or '1323442234' store = '1323442234' (skip first zero)
Upvotes: 2
Views: 1665
Reputation: 34718
There are a lot of way to remove 0
from the first part of a string.
If it contains only number, then cast it to integer
$var = (int)$var;
You can use left trim as follow :
$var = ltrim($var, '0');
Just use +
inside variables:
echo +$var;
Multiple it by 1 :
$var = "0000000000010";
print $var*1; // prints 10
Note : If your string contains without number, then only use ltrim
Upvotes: 2
Reputation: 11481
$trimmed_phone = ltrim($input, "0");
ltrim
will trim all the leading character from a string, no other characters will be removed.
doc: https://www.php.net/manual/en/function.ltrim.php
Upvotes: 2