Reputation: 31
I need to remove 0041 and 0 before Number because some users entered 0041 or 0 before 12345678. So, i just add 0041 static
$order->phone = "0041" . $request->phone;
So, if user entered 0041 or 0 before number it should be skipped and number will stored 004112345678.
Please give me any idea for it. Thanks
Upvotes: 1
Views: 162
Reputation: 34
if(preg_match("/^(0041|0)(?P<test>\d+)/", $number, $matches)){
$phone = "0041" . $matches['test'];
}
Upvotes: 1
Reputation: 34914
You can use str_pad
with fixed length 12
<?php
//$month = "004112345678";
$month = "012345678";
echo str_pad($month, 12, "0041xxxxxxxx", STR_PAD_LEFT);
?>
Upvotes: 1
Reputation: 12132
Use substr
to check for the first digits. Use it in a conditional as such:
if(substr($phone, 0, 4) !== "0041"){
$phone = "0041" . $phone;
}
Upvotes: 1