I have a database with 5000 entries of local area codes to separate the area code from a phone number string. Area Codes could be a part of other Area Codes. For example
0212 Solingen
02129 Haan
The Area Code of Solingen is a Part of the Area Code of Haan.
- Question: Should i store all entries in an array or should i search directly in SQL till the final result?
- Question: How can i get the entrie with the most found digits while area codes can be double in array / SQL
The Code i use is
The Result is "03491 52023" which is wrong; It should be "034915 2023"
<?php
$area_codes = array( '0350', '034', '034915', '03491', '0348', '0349', '03491', '034916', '034917',);
$phone = '0349152023';
foreach ($area_codes as $code) {
if (substr($phone, 0, strlen($code)) == $code) {
$phone_string = substr($phone, 0, strlen($code))." ".substr($phone, strlen($code));
}
}
if (!empty($phone_string)) {
echo $phone_string;
}
else {
echo "No AreaCode found.";
}
?>
Thanks for your help.