5
First doubt:
How to convert a phone book that is in format:
1188888888
1288888888
3188888888
1187877766
for:
11988888888
12988888888
31988888888
11987877766
via Notepad++ regular expression?
Or maybe if possible in PHP, as I have to loop several files. In case it is possible to do this "batch" in Notepad and someone can explain me xD
Remembering that the DDD can change. The entire list is for cell phones, so you don’t need confirmation to know if it is or isn’t. It would just need regex to move the first 2 houses and add the 9.
I tried to do adventures in PHP Dom but it didn’t work very well, let alone using fopen... I even managed to print the cool result, but I can’t export the final value back to csv. If this is the case, I will do it via Notepad++ even. It is more laborious, but it seems to be a simpler solution.
If anyone knows of an app or easier way to do this...
2nd doubt After the 9 digit has been added, I need to add a semicolon and the line count, which looks like this:
11988888888;1
12988888888;2
31988888888;3
11987877766;4
And of course, the list is huge, so I would need it to be very conventional. If you can do both at the same time with just 1 regex, it would be even nicer :D
PS: Now that I noticed that the last line of all the files is blank. That is, if there are 5000 lines in the file, 4999 has numbers, the last one is not. Soon the count should break only where it has number, not to "break" the file formatting.
Could anyone do that? Thank you :D
MY "SOLUTION" IN PHP (is not functional because it does not save the result, only shows on the screen)
<?php
$row = 1;
$handle = fopen ("Lista (1).csv","r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count ($data);
for ($c=0; $c < $num; $c++) {
$datanew = substr_replace($data, "9", 2, 0);
echo $datanew[$c]. ";$row <br />\n";
$row++;
}
}
fclose ($handle);
?>
But it only prints on the screen. I couldn’t get it to overwrite the file.
If you did, create an answer don’t put that code in the question. xD is more or less what I was doing with php
– rray
I could not because it is not fully functional. It does not save the file. It just shows on the screen =/
– Diego
you can create a new file with the modifications using
fopen
withw+
, to add to the;
and the line number follows the same logic as thesubstr_replace()
.– rray
Could you show me how to do this? I’m a beginner in php, some things I only learn by seeing xD. I’m taking classes at Cursoemvideo.com with Gustavo Guanabara.
– Diego
In csv, there’s only one phone per line?
– rray
Exactly, 1 line per phone. Need to convert to 9th digit and still put semicolon and line count in front.
– Diego
You need to check a few more things, such as the "special cases" and also the Nextel numbers.
– David Schrammel
There are no "special cases" or Nextel numbers. Lists are basic numbers, all have DDD at the beginning followed by 8 digits. And they are all mobile. That is, I don’t need the script to do checks, it can be a "dumb" script that puts the 9 in the third house and the end semicolon and the line count. No problem.
– Diego