I have the following PHP code that is suppose to remove the 'excess' text when a user enters it in a field. I have the following code as follows:
$mobileNumber = '00 356 99048123';
$excessMobileNumbers = array(//remove excess items in mobile number such as dialing codes and empty spaces
// ' ' => '',
'00356' => '',
'+356' => '',
'356' => '',
'00' => '',
);
The output is 99048123
The above code works well as it the number 99048123 doesn't contain 356 or 00.
But when I use this number 00 356 99008123, the number 99008123 contains 00. I want it only to remove the 00 in the 00 i.e. starting from the left hand side and leaving without removing the 00 in the 99008123.
How do I go about it? I use the array as a 'filtering' system.
Thanks
Clarification It is not only for 00 even for 356, if the number is 99048123 it works fine. If this number 99035612 since it has 356 withing it it does not work.
SOLUTION I discovered this solution which seems to work for my problem.
$mobileNumber = '00 356 99048000';
$mobileNumber = str_replace(' ','',$mobileNumber); // UPDATE
$excessMobileNumbers = substr($mobileNumber, 0, -8);
$mobileNumber = str_replace($excessMobileNumbers,'',$mobileNumber);
echo $mobileNumber;
Thank you all for your contribution.