Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

International area code ignored #193

Open
obnys opened this issue Jan 19, 2020 · 12 comments · May be fixed by #216
Open

International area code ignored #193

obnys opened this issue Jan 19, 2020 · 12 comments · May be fixed by #216

Comments

@obnys
Copy link

obnys commented Jan 19, 2020

Greetings,
since import without FTP is working, I noticed today, that the international area code is beeing ignored with the imported data.
e.g. +49 1234 987654 has been imported as 1234 987654, so the leading "0" has not been added while the international area code has been ignored.
Are there intensions to add this? Otherwise I would just use 0049 1234 987654 or leave the area code aside as long as the number is in the same country.

@andig
Copy link
Owner

andig commented Jan 20, 2020

See https://github.com/andig/carddav2fb/blob/master/config.example.php#L100. Seems our default settings arent very good and we should replace with 0 instead of empty?

@obnys
Copy link
Author

obnys commented Jan 20, 2020

Oh dear, I'm sorry, I didn't notice I could just adjust the config.php. Now it works perfectly! Again thanks a lot! =)
But you're right. "+49" it should either be replaced with '0049' or '0', instead of '' by default.

@blacksenator
Copy link
Collaborator

blacksenator commented Jan 20, 2020

@obnys here a suggestion:

'phoneReplaceCharacters' => [          // are processed consecutively. Order decides!
    '('     => '',                          // delete separators
    ')'     => '',
    '/'     => '',
    '-'     => '',
    ' '     => '',
    '+491'  => '01',                   // domestic numbers without country code
    '+492'  => '02',
    '+493'  => '03',
    '+494'  => '04',
    '+495'  => '05',
    '+496'  => '06',
    '+497'  => '07',
    '+498'  => '08',
    '+499'  => '09',
    '+49'   => '',
    '+'     => '00'                    // normalize foreign numbers
]

@obnys
Copy link
Author

obnys commented Jan 20, 2020

Thank you @blacksenator =)
But wouldn't this already be sufficient?

...
'+49'  => '0',
'0049'  => '0',
'+'     => '00',    // keep international area codes for foreign countries intact.
...

Do you think I would really need to add an entry for each area code digit from 1-9?

@andig
Copy link
Owner

andig commented Jan 20, 2020

But wouldn't this already be sufficient?

Think so. Would you kindly open a PR?

@blacksenator
Copy link
Collaborator

blacksenator commented Jan 20, 2020

@obnys

But wouldn't this already be sufficient?

That depends on your source data and what you want to receive.
I only want to have digits as numbers:
03667337171 for domestic numbers
or
001476458488 for foreign numbers

I just made a few tests with my data and only this works for me:

'phoneReplaceCharacters' => [          // are processed consecutively. Order decides!
    '('     => '',                     // delete separators
    ')'     => '',
    '/'     => '',
    '-'     => '',
    ' '     => '',
    '+49 1'  => '01',                   // domestic numbers without area code
    '+49 2'  => '02',
    '+49 3'  => '03',
    '+49 4'  => '04',
    '+49 5'  => '05',
    '+49 6'  => '06',
    '+49 7'  => '07',
    '+49 8'  => '08',
    '+49 9'  => '09',
    '+491'  => '01',
    '+492'  => '02',
    '+493'  => '03',
    '+494'  => '04',
    '+495'  => '05',
    '+496'  => '06',
    '+497'  => '07',
    '+498'  => '08',
    '+499'  => '09',
    '+49'   => '',
    '+'     => '00'                    // normalize foreign numbers
]

@andig - I never thought about this line - so I tried to find information about how strstr works with assoziativ array (like in this way) - but couldn´t find any proper information.

@andig
Copy link
Owner

andig commented Jan 20, 2020

I never thought about this line - so I tried to find information about how strstr works with assoziativ array (like in this way) - but couldn´t find any proper information.

The thing is that strtr will replace verbatim, the array case is documented, too. Longest matches are processed first.

We're not using a regex here. Therefore:

$replace = [
    '+49' => '0',
    '+49 ' => '0',
];

echo(strtr('+49 151 4711', $replace)."\n");

gives

0151 4711

if you omit the second replacement you'll get

0 151 4711

which is ugly. So remember the variant with the space.

Would like a see a PR for improving the default config ;)

@obnys
Copy link
Author

obnys commented Jan 20, 2020

Oki, I made a pull request and somehow it landed at jens-maus. I hope I did it correct. Sorry, never did that before and I have zero experience with GitHub :-P

@andig
Copy link
Owner

andig commented Jan 21, 2020 via email

@blacksenator
Copy link
Collaborator

I have lost track of who is waiting for whom with a PR!

@andig When I wrote the line "I never thought about this line ..." I had overlooked the fact that it was strtr and not strstr. My confusion cleared up after reading the documentation for strtr.

@andig
Copy link
Owner

andig commented Feb 11, 2020

Ping @obnys would you mind to open another PR against this repo?

@hanzi hanzi linked a pull request Aug 11, 2020 that will close this issue
@blacksenator
Copy link
Collaborator

I can't see a reason keeping this issue open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants