How to skip first zero in the entry form in Laravel?

Viewed 793

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)

2 Answers

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

Related