Contribution Date
Technology
Contribution Project
Contribution Details
I have got solution by customizing some of the code:
Original code:
$areacode = $localnumber = '';
// Mobile number
if (preg_match('/([0]{1}[6]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){7})/', $phonenumber)) {
preg_match('/(?[0]{1}[6]{1})[-\s]+(?[1-9]{1}[\s]*([0-9]{1}[\s]*){7})/', $phonenumber, $matches);
}
// Phonenumber with 4 digit area code
if (preg_match('/([0]{1}[1-9]{1}[0-9]{2}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){5})/', $phonenumber)) {
preg_match('/(?[0]{1}[1-9]{1}[0-9]{2})[-\s]+(?[1-9]{1}[\s]*([0-9]{1}[\s]*){5})/', $phonenumber, $matches);
}
// Phonenumber with 3 digit area code
if (preg_match('/([0]{1}[1-9]{1}[0-9]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){6})/', $phonenumber)) {
preg_match('/(?[0]{1}[1-9]{1}[0-9]{1})[-\s]+(?[1-9]{1}[\s]*([0-9]{1}[\s]*){6})/', $phonenumber, $matches);
}
$areacode = $matches[areacode];
$localnumber = preg_replace('/ /', '', $matches[localnumber]);
$phonenumber = $areacode. '-'. $localnumber;
// Add Country code if needed
if ($field['phone_country_code']) {
$areacode = preg_replace('/^0/', '', $areacode);
$phonenumber = '+31-'. $areacode. '-'. $localnumber;
}
============================
My modified code:
$areacode = $localnumber = '';
// Mobile number
if (preg_match('/([0]{1}[6]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){7})/', $phonenumber)) {
preg_match('/([0]{1}[6]{1})[-\s]+([1-9]{1}[\s]*([0-9]{1}[\s]*){7})/', $phonenumber, $matches);
}
// Phonenumber with 4 digit area code
if (preg_match('/([0]{1}[1-9]{1}[0-9]{2}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){5})/', $phonenumber)) {
preg_match('/([0]{1}[1-9]{1}[0-9]{2})[-\s]+([1-9]{1}[\s]*([0-9]{1}[\s]*){5})/', $phonenumber, $matches);
}
// Phonenumber with 3 digit area code
if (preg_match('/([0]{1}[1-9]{1}[0-9]{1}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){6})/', $phonenumber)) {
preg_match('/([0]{1}[1-9]{1}[0-9]{1})[-\s]+([1-9]{1}[\s]*([0-9]{1}[\s]*){6})/', $phonenumber, $matches);
}
$areacode = $matches[1];
$localnumber = preg_replace('/ /', '', $matches[2]);
$phonenumber = $areacode. '-'. $localnumber;
// Add Country code if needed
if ($field['phone_country_code']) {
$areacode = preg_replace('/^0/', '', $areacode);
$phonenumber = '+31-'. $areacode. '-'. $localnumber;
}
I have removed variables areacode and local number form the original code.
And access others using the array index
Contribution Issue Link
Contribution Link
Files count
0
Patches count
0