How to convert a string php?

Good afternoon.
I have two tables. In each table there is a field 'phone', which contains a telephone number, but the problem is that the table And the phone written in the form "+79876543210", and table B in the form of "+7 (987) 654-32-10".
I need to take a number from the table and check for matches in table B.
What are the options?
I was considering either convert to request view And room B.
Or if possible some simple way to 5500+ rooms in the table B to mean the numbers from table A.
Actually a question - how to convert to query the number of species And number of the form B?
Or how to walk on table B and convert all the numbers?
March 23rd 20 at 18:50
2 answers
March 23rd 20 at 18:52
In short, Maxim, I saved you and the nobility will not play: perform for me a couple of features - and we're even. At the same time see how quickly your brain after learning php will become clear. But on your topic I already found out. Fuck knows why you got them so the data store surrendered, but I'm in other people's Affairs do not climb. Want to keep - then you have something...
In the previous question you said that you are getting the json from Yandex.telephony, apparently you're still struggling with it. Yandex transmits data in the format "+79876543210", and in response to Mr @sv09 you mentioned that you get phones with a form on the website, and apparently with the help of the placeholder in the form "+7 (987) 654-32-10".
And now you're trying for some reason to compare the data of Yandex and on your website.
In short, if all that you do in the file that you have writes the data into a database from forms on the website, the following:
$phone = preg_replace("/[^+0-9]/s", "", strip_tags(trim($_POST['phone'])));
Where $phone is, accordingly, a variable that receives the data from the field "phone" in the form.
So you get in your database phone view +79876543210. And then compare them all you want,
This is the easiest option :)
If you need to go through the database and modify all of phones, then make a separate question.
@sv09, I doubt that he had such volumes of data where speed is the deciding factor :)
About plus agree. - dangelo.Zemlak commented on March 23rd 20 at 18:55
Plus from a phone number cannot be deleted, without it, the room becomes defective, not corresponding to the telephone standard.

And in the database just run the command:
UPDATE table_b SET phone=REPLACE(' ', ", REPLACE('(', ", REPLACE(')', ", REPLACE('-', ", phone))));

in table table_b will be required, without -() and spaces. - Breanna_Friesen commented on March 23rd 20 at 18:58
@Breanna_Friesen, I have lost all phone numbers from this query) - dangelo.Zemlak commented on March 23rd 20 at 19:01
Oh, mia culpa again mixed up the sequence of arguments...
UPDATE table_b SET phone=REPLACE(REPLACE(REPLACE(REPLACE(phone, '-', "), ')', "), '(', "), ' ', ");
- Breanna_Friesen commented on March 23rd 20 at 19:04
@Breanna_Friesen, and all the phones are the same :) - dangelo.Zemlak commented on March 23rd 20 at 19:07
@dangelo.Zemlak, so should not be. And before executing this command, the phone just different? - Breanna_Friesen commented on March 23rd 20 at 19:10
@Breanna_Friesen, about 6000 different phones :)
And after this function is taken from the phone of the first cell and assign all the rest - dangelo.Zemlak commented on March 23rd 20 at 19:13
@dangelo.Zemlak, a strange behavior of SQL. Or framework, which is used to access MySQL.
If you have access to MySQL through the console - run it. Or in PHP script using direct mysql_connect() the connection.
Because well, not need UPDATE statement to use the same number for all records... - Breanna_Friesen commented on March 23rd 20 at 19:16
@Breanna_Friesen, I write in pure php, and this code was executed directly in phpmyadmin) - dangelo.Zemlak commented on March 23rd 20 at 19:19
Well then the last, literally the final attempt:
UPDATE `table_b` SET `phone`=REPLACE(REPLACE(REPLACE(REPLACE(`phone`, '-', "), ')', "), '(', "), ' ', ") WHERE 1

and there are more options. Well vaabsche no. - Breanna_Friesen commented on March 23rd 20 at 19:22
March 23rd 20 at 18:54
Need from the string remove all characters except numbers and compare the cleaned rooms.
Through replace, but you can in the regular season.
Well, obviously, Yes. BUT. I take the phone view +79876543210 and do a select on the table where the phone numbers of another species. How, then, can I delete characters? - dangelo.Zemlak commented on March 23rd 20 at 18:57
@dangelo.Zemlak, in this case, you need to do the replace directly in a query... (in MySQL queries can also be used of the regular season). - kendra.Toy commented on March 23rd 20 at 19:00
@dangelo.Zemlak, at the time of saving to the table. Or write a script that will execute once the normalization of the existing data in the database, and then work with them in other scripts not bothered. - curtis.Braun commented on March 23rd 20 at 19:03
@curtis.Braun, in the case of the script it will be necessary periodically to run it when the table changes - dereck_Ryan94 commented on March 23rd 20 at 19:06
@curtis.Braun, Yes, I am clear in the moment of recording in the database, the easiest way. - dangelo.Zemlak commented on March 23rd 20 at 19:09

Find more questions by tags MySQLPHP