Separate areacode from phone number string with MySQL Database
I have a database with 5000 entries of local area codes to separate the area code from a phone number string. I'm not sure if the code
I use is the fastest way to solve these job.
I shrink the number of db entries with the first three digits from phone number string. After this I put the entries found in db in an array and finally search these array for a match.
What do you think guys? Would you do it the same?
<?php
$phonenumber = '03522522492';
$country = 'DE';
$link = mysqli_connect('Host', 'DB', 'Pass','User') or die(mysqli_error());
$db_selected = mysqli_select_db( $link, 'DB');
$fristthree = substr($phonenumber,0,3);
$array = array();
$query = mysqli_query($link, "SELECT * FROM `Areacodes` WHERE `Country` LIKE '".$country."%' AND `Areacode` like '".$fristthree."%' ORDER BY CHAR_LENGTH(Areacode) ASC");
while($row = mysqli_fetch_assoc($query)){
$array = $row;
}
foreach ($array as $areacode) {
$subString = substr($phonenumber, 0, strlen($areacode["Areacode"]));
if ($subString == $areacode["Areacode"]) {
$phone = $subString." ".substr($phonenumber, strlen($areacode["Areacode"]));
$location = $areacode["Location"];
}
}
if (!empty($phone)) {
echo $phone;
echo '<br><br>';
echo $subString;
echo '<br><br>';
echo $location;
}
else {
echo "No Areacode found.";
}
?>
php mysql mysqli
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have a database with 5000 entries of local area codes to separate the area code from a phone number string. I'm not sure if the code
I use is the fastest way to solve these job.
I shrink the number of db entries with the first three digits from phone number string. After this I put the entries found in db in an array and finally search these array for a match.
What do you think guys? Would you do it the same?
<?php
$phonenumber = '03522522492';
$country = 'DE';
$link = mysqli_connect('Host', 'DB', 'Pass','User') or die(mysqli_error());
$db_selected = mysqli_select_db( $link, 'DB');
$fristthree = substr($phonenumber,0,3);
$array = array();
$query = mysqli_query($link, "SELECT * FROM `Areacodes` WHERE `Country` LIKE '".$country."%' AND `Areacode` like '".$fristthree."%' ORDER BY CHAR_LENGTH(Areacode) ASC");
while($row = mysqli_fetch_assoc($query)){
$array = $row;
}
foreach ($array as $areacode) {
$subString = substr($phonenumber, 0, strlen($areacode["Areacode"]));
if ($subString == $areacode["Areacode"]) {
$phone = $subString." ".substr($phonenumber, strlen($areacode["Areacode"]));
$location = $areacode["Location"];
}
}
if (!empty($phone)) {
echo $phone;
echo '<br><br>';
echo $subString;
echo '<br><br>';
echo $location;
}
else {
echo "No Areacode found.";
}
?>
php mysql mysqli
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
note that even your trick with ordering codes from the longest to shortest may give a false positive, as the actual phone number may start from the remainder of the longer code, i.e. there are two codes, 03254 and 032. Given the phone number is (032)5442211, it will detect the wrong area code.
– Your Common Sense
Oct 12 '17 at 11:29
And, given such a task, I would refuse to solve it directly. There is not enough info to do it well
– Your Common Sense
Oct 12 '17 at 11:30
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 032, 0325, 03254 and 032544 you would expected the location of 032544 for 03522522492?
– mheinzerling
Oct 12 '17 at 11:52
@YourCommonSense: Hi Thanks for your response and your note. If a areacode 03254 exists the call number of 032 can't start with 5 in Germany. But you are right, maybe the problem can appear in other countrys
– soo29
Oct 12 '17 at 13:06
@mheinzerling: Yes. I have a string for example "03522522492" and spilt the string into areacode and call number. In germany we have 5000 different areacodes with digits from 3 to 6.
– soo29
Oct 12 '17 at 13:08
add a comment |
I have a database with 5000 entries of local area codes to separate the area code from a phone number string. I'm not sure if the code
I use is the fastest way to solve these job.
I shrink the number of db entries with the first three digits from phone number string. After this I put the entries found in db in an array and finally search these array for a match.
What do you think guys? Would you do it the same?
<?php
$phonenumber = '03522522492';
$country = 'DE';
$link = mysqli_connect('Host', 'DB', 'Pass','User') or die(mysqli_error());
$db_selected = mysqli_select_db( $link, 'DB');
$fristthree = substr($phonenumber,0,3);
$array = array();
$query = mysqli_query($link, "SELECT * FROM `Areacodes` WHERE `Country` LIKE '".$country."%' AND `Areacode` like '".$fristthree."%' ORDER BY CHAR_LENGTH(Areacode) ASC");
while($row = mysqli_fetch_assoc($query)){
$array = $row;
}
foreach ($array as $areacode) {
$subString = substr($phonenumber, 0, strlen($areacode["Areacode"]));
if ($subString == $areacode["Areacode"]) {
$phone = $subString." ".substr($phonenumber, strlen($areacode["Areacode"]));
$location = $areacode["Location"];
}
}
if (!empty($phone)) {
echo $phone;
echo '<br><br>';
echo $subString;
echo '<br><br>';
echo $location;
}
else {
echo "No Areacode found.";
}
?>
php mysql mysqli
I have a database with 5000 entries of local area codes to separate the area code from a phone number string. I'm not sure if the code
I use is the fastest way to solve these job.
I shrink the number of db entries with the first three digits from phone number string. After this I put the entries found in db in an array and finally search these array for a match.
What do you think guys? Would you do it the same?
<?php
$phonenumber = '03522522492';
$country = 'DE';
$link = mysqli_connect('Host', 'DB', 'Pass','User') or die(mysqli_error());
$db_selected = mysqli_select_db( $link, 'DB');
$fristthree = substr($phonenumber,0,3);
$array = array();
$query = mysqli_query($link, "SELECT * FROM `Areacodes` WHERE `Country` LIKE '".$country."%' AND `Areacode` like '".$fristthree."%' ORDER BY CHAR_LENGTH(Areacode) ASC");
while($row = mysqli_fetch_assoc($query)){
$array = $row;
}
foreach ($array as $areacode) {
$subString = substr($phonenumber, 0, strlen($areacode["Areacode"]));
if ($subString == $areacode["Areacode"]) {
$phone = $subString." ".substr($phonenumber, strlen($areacode["Areacode"]));
$location = $areacode["Location"];
}
}
if (!empty($phone)) {
echo $phone;
echo '<br><br>';
echo $subString;
echo '<br><br>';
echo $location;
}
else {
echo "No Areacode found.";
}
?>
php mysql mysqli
php mysql mysqli
edited Jan 10 '18 at 19:40
Sᴀᴍ Onᴇᴌᴀ
8,43261854
8,43261854
asked Oct 12 '17 at 11:19
soo29
62
62
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
note that even your trick with ordering codes from the longest to shortest may give a false positive, as the actual phone number may start from the remainder of the longer code, i.e. there are two codes, 03254 and 032. Given the phone number is (032)5442211, it will detect the wrong area code.
– Your Common Sense
Oct 12 '17 at 11:29
And, given such a task, I would refuse to solve it directly. There is not enough info to do it well
– Your Common Sense
Oct 12 '17 at 11:30
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 032, 0325, 03254 and 032544 you would expected the location of 032544 for 03522522492?
– mheinzerling
Oct 12 '17 at 11:52
@YourCommonSense: Hi Thanks for your response and your note. If a areacode 03254 exists the call number of 032 can't start with 5 in Germany. But you are right, maybe the problem can appear in other countrys
– soo29
Oct 12 '17 at 13:06
@mheinzerling: Yes. I have a string for example "03522522492" and spilt the string into areacode and call number. In germany we have 5000 different areacodes with digits from 3 to 6.
– soo29
Oct 12 '17 at 13:08
add a comment |
1
note that even your trick with ordering codes from the longest to shortest may give a false positive, as the actual phone number may start from the remainder of the longer code, i.e. there are two codes, 03254 and 032. Given the phone number is (032)5442211, it will detect the wrong area code.
– Your Common Sense
Oct 12 '17 at 11:29
And, given such a task, I would refuse to solve it directly. There is not enough info to do it well
– Your Common Sense
Oct 12 '17 at 11:30
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 032, 0325, 03254 and 032544 you would expected the location of 032544 for 03522522492?
– mheinzerling
Oct 12 '17 at 11:52
@YourCommonSense: Hi Thanks for your response and your note. If a areacode 03254 exists the call number of 032 can't start with 5 in Germany. But you are right, maybe the problem can appear in other countrys
– soo29
Oct 12 '17 at 13:06
@mheinzerling: Yes. I have a string for example "03522522492" and spilt the string into areacode and call number. In germany we have 5000 different areacodes with digits from 3 to 6.
– soo29
Oct 12 '17 at 13:08
1
1
note that even your trick with ordering codes from the longest to shortest may give a false positive, as the actual phone number may start from the remainder of the longer code, i.e. there are two codes, 03254 and 032. Given the phone number is (032)5442211, it will detect the wrong area code.
– Your Common Sense
Oct 12 '17 at 11:29
note that even your trick with ordering codes from the longest to shortest may give a false positive, as the actual phone number may start from the remainder of the longer code, i.e. there are two codes, 03254 and 032. Given the phone number is (032)5442211, it will detect the wrong area code.
– Your Common Sense
Oct 12 '17 at 11:29
And, given such a task, I would refuse to solve it directly. There is not enough info to do it well
– Your Common Sense
Oct 12 '17 at 11:30
And, given such a task, I would refuse to solve it directly. There is not enough info to do it well
– Your Common Sense
Oct 12 '17 at 11:30
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 032, 0325, 03254 and 032544 you would expected the location of 032544 for 03522522492?
– mheinzerling
Oct 12 '17 at 11:52
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 032, 0325, 03254 and 032544 you would expected the location of 032544 for 03522522492?
– mheinzerling
Oct 12 '17 at 11:52
@YourCommonSense: Hi Thanks for your response and your note. If a areacode 03254 exists the call number of 032 can't start with 5 in Germany. But you are right, maybe the problem can appear in other countrys
– soo29
Oct 12 '17 at 13:06
@YourCommonSense: Hi Thanks for your response and your note. If a areacode 03254 exists the call number of 032 can't start with 5 in Germany. But you are right, maybe the problem can appear in other countrys
– soo29
Oct 12 '17 at 13:06
@mheinzerling: Yes. I have a string for example "03522522492" and spilt the string into areacode and call number. In germany we have 5000 different areacodes with digits from 3 to 6.
– soo29
Oct 12 '17 at 13:08
@mheinzerling: Yes. I have a string for example "03522522492" and spilt the string into areacode and call number. In germany we have 5000 different areacodes with digits from 3 to 6.
– soo29
Oct 12 '17 at 13:08
add a comment |
1 Answer
1
active
oldest
votes
Assuming my understanding of the question and the data is correct:
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 035, 0352, 03522 and 035225 you would expected the location of 035225 for 03522522492?
I would try a SQL-only approach:
SELECT *
FROM Areacodes
WHERE Areacode IN ('032','0352','03522','035225')
ORDER BY CHAR_LENGTH(deliveryAddress_zip) DESC
LIMIT 0,1
So in PHP you now only need to build the IN-clause. Split the phone number in substrings of suitable length (I guess 3-6 digits for Germany).
Without any validation the snipped could look like:
$phone = "03522522492";
$parts = ;
for ($len = 3; $len <= 6; $len++) $parts = substr($phone, 0, $len);
$in = "'" . implode("','", $parts) . "'";
echo $in;
//'035','0352','03522','035225'
@Did I get it right that you want to map your phone number to the area matching the most initial digits? Yes that's right
– soo29
Oct 12 '17 at 13:10
Ok, so my solution should work. As I said, you just need to generate a suitable IN-clause.
– mheinzerling
Oct 12 '17 at 13:13
Having "032, 035, 0352, 03522, 035225, 03254, 032544" in MySQL i would expected the location of 035225 for the phone number string 03522522492?
– soo29
Oct 12 '17 at 13:14
I don't understand your line "WHERE Areacode IN ('032','0325','03254','032544') " how do you get to the digits? The script starts with the entry of the phone number, for example 03522522492.
– soo29
Oct 12 '17 at 13:24
I added the php part
– mheinzerling
Oct 12 '17 at 13:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f177754%2fseparate-areacode-from-phone-number-string-with-mysql-database%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming my understanding of the question and the data is correct:
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 035, 0352, 03522 and 035225 you would expected the location of 035225 for 03522522492?
I would try a SQL-only approach:
SELECT *
FROM Areacodes
WHERE Areacode IN ('032','0352','03522','035225')
ORDER BY CHAR_LENGTH(deliveryAddress_zip) DESC
LIMIT 0,1
So in PHP you now only need to build the IN-clause. Split the phone number in substrings of suitable length (I guess 3-6 digits for Germany).
Without any validation the snipped could look like:
$phone = "03522522492";
$parts = ;
for ($len = 3; $len <= 6; $len++) $parts = substr($phone, 0, $len);
$in = "'" . implode("','", $parts) . "'";
echo $in;
//'035','0352','03522','035225'
@Did I get it right that you want to map your phone number to the area matching the most initial digits? Yes that's right
– soo29
Oct 12 '17 at 13:10
Ok, so my solution should work. As I said, you just need to generate a suitable IN-clause.
– mheinzerling
Oct 12 '17 at 13:13
Having "032, 035, 0352, 03522, 035225, 03254, 032544" in MySQL i would expected the location of 035225 for the phone number string 03522522492?
– soo29
Oct 12 '17 at 13:14
I don't understand your line "WHERE Areacode IN ('032','0325','03254','032544') " how do you get to the digits? The script starts with the entry of the phone number, for example 03522522492.
– soo29
Oct 12 '17 at 13:24
I added the php part
– mheinzerling
Oct 12 '17 at 13:34
add a comment |
Assuming my understanding of the question and the data is correct:
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 035, 0352, 03522 and 035225 you would expected the location of 035225 for 03522522492?
I would try a SQL-only approach:
SELECT *
FROM Areacodes
WHERE Areacode IN ('032','0352','03522','035225')
ORDER BY CHAR_LENGTH(deliveryAddress_zip) DESC
LIMIT 0,1
So in PHP you now only need to build the IN-clause. Split the phone number in substrings of suitable length (I guess 3-6 digits for Germany).
Without any validation the snipped could look like:
$phone = "03522522492";
$parts = ;
for ($len = 3; $len <= 6; $len++) $parts = substr($phone, 0, $len);
$in = "'" . implode("','", $parts) . "'";
echo $in;
//'035','0352','03522','035225'
@Did I get it right that you want to map your phone number to the area matching the most initial digits? Yes that's right
– soo29
Oct 12 '17 at 13:10
Ok, so my solution should work. As I said, you just need to generate a suitable IN-clause.
– mheinzerling
Oct 12 '17 at 13:13
Having "032, 035, 0352, 03522, 035225, 03254, 032544" in MySQL i would expected the location of 035225 for the phone number string 03522522492?
– soo29
Oct 12 '17 at 13:14
I don't understand your line "WHERE Areacode IN ('032','0325','03254','032544') " how do you get to the digits? The script starts with the entry of the phone number, for example 03522522492.
– soo29
Oct 12 '17 at 13:24
I added the php part
– mheinzerling
Oct 12 '17 at 13:34
add a comment |
Assuming my understanding of the question and the data is correct:
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 035, 0352, 03522 and 035225 you would expected the location of 035225 for 03522522492?
I would try a SQL-only approach:
SELECT *
FROM Areacodes
WHERE Areacode IN ('032','0352','03522','035225')
ORDER BY CHAR_LENGTH(deliveryAddress_zip) DESC
LIMIT 0,1
So in PHP you now only need to build the IN-clause. Split the phone number in substrings of suitable length (I guess 3-6 digits for Germany).
Without any validation the snipped could look like:
$phone = "03522522492";
$parts = ;
for ($len = 3; $len <= 6; $len++) $parts = substr($phone, 0, $len);
$in = "'" . implode("','", $parts) . "'";
echo $in;
//'035','0352','03522','035225'
Assuming my understanding of the question and the data is correct:
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 035, 0352, 03522 and 035225 you would expected the location of 035225 for 03522522492?
I would try a SQL-only approach:
SELECT *
FROM Areacodes
WHERE Areacode IN ('032','0352','03522','035225')
ORDER BY CHAR_LENGTH(deliveryAddress_zip) DESC
LIMIT 0,1
So in PHP you now only need to build the IN-clause. Split the phone number in substrings of suitable length (I guess 3-6 digits for Germany).
Without any validation the snipped could look like:
$phone = "03522522492";
$parts = ;
for ($len = 3; $len <= 6; $len++) $parts = substr($phone, 0, $len);
$in = "'" . implode("','", $parts) . "'";
echo $in;
//'035','0352','03522','035225'
edited Oct 12 '17 at 13:33
answered Oct 12 '17 at 12:13
mheinzerling
2,644817
2,644817
@Did I get it right that you want to map your phone number to the area matching the most initial digits? Yes that's right
– soo29
Oct 12 '17 at 13:10
Ok, so my solution should work. As I said, you just need to generate a suitable IN-clause.
– mheinzerling
Oct 12 '17 at 13:13
Having "032, 035, 0352, 03522, 035225, 03254, 032544" in MySQL i would expected the location of 035225 for the phone number string 03522522492?
– soo29
Oct 12 '17 at 13:14
I don't understand your line "WHERE Areacode IN ('032','0325','03254','032544') " how do you get to the digits? The script starts with the entry of the phone number, for example 03522522492.
– soo29
Oct 12 '17 at 13:24
I added the php part
– mheinzerling
Oct 12 '17 at 13:34
add a comment |
@Did I get it right that you want to map your phone number to the area matching the most initial digits? Yes that's right
– soo29
Oct 12 '17 at 13:10
Ok, so my solution should work. As I said, you just need to generate a suitable IN-clause.
– mheinzerling
Oct 12 '17 at 13:13
Having "032, 035, 0352, 03522, 035225, 03254, 032544" in MySQL i would expected the location of 035225 for the phone number string 03522522492?
– soo29
Oct 12 '17 at 13:14
I don't understand your line "WHERE Areacode IN ('032','0325','03254','032544') " how do you get to the digits? The script starts with the entry of the phone number, for example 03522522492.
– soo29
Oct 12 '17 at 13:24
I added the php part
– mheinzerling
Oct 12 '17 at 13:34
@Did I get it right that you want to map your phone number to the area matching the most initial digits? Yes that's right
– soo29
Oct 12 '17 at 13:10
@Did I get it right that you want to map your phone number to the area matching the most initial digits? Yes that's right
– soo29
Oct 12 '17 at 13:10
Ok, so my solution should work. As I said, you just need to generate a suitable IN-clause.
– mheinzerling
Oct 12 '17 at 13:13
Ok, so my solution should work. As I said, you just need to generate a suitable IN-clause.
– mheinzerling
Oct 12 '17 at 13:13
Having "032, 035, 0352, 03522, 035225, 03254, 032544" in MySQL i would expected the location of 035225 for the phone number string 03522522492?
– soo29
Oct 12 '17 at 13:14
Having "032, 035, 0352, 03522, 035225, 03254, 032544" in MySQL i would expected the location of 035225 for the phone number string 03522522492?
– soo29
Oct 12 '17 at 13:14
I don't understand your line "WHERE Areacode IN ('032','0325','03254','032544') " how do you get to the digits? The script starts with the entry of the phone number, for example 03522522492.
– soo29
Oct 12 '17 at 13:24
I don't understand your line "WHERE Areacode IN ('032','0325','03254','032544') " how do you get to the digits? The script starts with the entry of the phone number, for example 03522522492.
– soo29
Oct 12 '17 at 13:24
I added the php part
– mheinzerling
Oct 12 '17 at 13:34
I added the php part
– mheinzerling
Oct 12 '17 at 13:34
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f177754%2fseparate-areacode-from-phone-number-string-with-mysql-database%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
note that even your trick with ordering codes from the longest to shortest may give a false positive, as the actual phone number may start from the remainder of the longer code, i.e. there are two codes, 03254 and 032. Given the phone number is (032)5442211, it will detect the wrong area code.
– Your Common Sense
Oct 12 '17 at 11:29
And, given such a task, I would refuse to solve it directly. There is not enough info to do it well
– Your Common Sense
Oct 12 '17 at 11:30
Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 032, 0325, 03254 and 032544 you would expected the location of 032544 for 03522522492?
– mheinzerling
Oct 12 '17 at 11:52
@YourCommonSense: Hi Thanks for your response and your note. If a areacode 03254 exists the call number of 032 can't start with 5 in Germany. But you are right, maybe the problem can appear in other countrys
– soo29
Oct 12 '17 at 13:06
@mheinzerling: Yes. I have a string for example "03522522492" and spilt the string into areacode and call number. In germany we have 5000 different areacodes with digits from 3 to 6.
– soo29
Oct 12 '17 at 13:08