here again requesting your help and I hope you can help me create this instruction.
I want to create a php script that reads a flat file and substitutes a string of characters, that string of characters is identified with a regular expression that I created for it.
I am using preg_replace since it allows me to replace strings based on regular expressions. If you did it from the php file it works great for me, the issue is that it's a batch of files, so I have to read them, look for the regular expression, replace that information, save the file and you're done.
The most I have managed to do is the following, I know I need a touch but I could not see it. I must be doing something wrong. The sample flat file goes like this:
11/29/18 11:07 a. m. - Noemi Venaim Broker: Parral selling wide apt 160mts. 3hab more service. 3 bathrooms. 2 points Fitted kitchen. Young Edf with beautiful social areas. Panoramic view. Power plant. Price of opportunity Ref 35.000 NEGOTIALES.
11/29/18 11:58 a. m. - Luisana Tavare Corredora: Luisana tavare sells land in la morocha variety of options with and without pool, more inf 04144301822
The regular expression to look for would be this:
$patron = '/\d{2}\/\d{2}\/\d{2}..............\-/m';
What will you take as a value:
$sustitucion = '|2018-11-29|';
That is, it is replaced from "11/29/18 11:58 AM -" by "| 2018-11-29 |"
And the complete code would be this:
$archivo = "prueba.txt";
$abrir = fopen('prueba.txt', 'r+');
$data = fread($abrir, filesize($archivo));
$patron = '/\d{2}\/\d{2}\/\d{2}..............\-/m';
$sustitucion = '|2018-11-29|';
$datosnuevos = preg_replace($patron, $sustitucion, $data);
fwrite($abrir, $datosnuevos);
fclose($abrir);
The result I get with this code is the following:
11/29/18 11:07 a. m. - Noemi Venaim Broker: Parral selling ample apt 160mts. 3hab more service. 3 bathrooms. 2 points Fitted kitchen. Edf Young with beautiful social areas. Panoramic view. Power plant. Price of opportunity Ref 35.000 NEGOTIALES.
11/29/18 11:58 a. m. - Luisana Tavare Corredora: Luisana tavare sells land plots in la morocha variety of options with and without a pool, more inf 04144301822 | 2018-11-29 | Noemi Venaim Broker: Parral I sell wide apt 160mts. 3hab more service. 3 bathrooms. 2 points Fitted kitchen. Young Edf with beautiful social areas. Panoramic view. Power plant. Price of opportunity Ref 35.000 NEGOTIALES. 2018-11-29 | Luisana Tavare Corredora: Luisana tavare sells land in la morocha variety of options with and without pool, more inf 04144301822
And what I want is for you to do this to me:
| 2018-11-29 | Noemi Venaim Broker: Parral I sell wide apt 160mts. 3hab more service. 3 bathrooms. 2 points Fitted kitchen. Young Edf with beautiful social areas. Panoramic view. Power plant. Price of opportunity Ref 35.000 NEGOTIALES.
2018-11-29 | Luisana Tavare Corredora: Luisana tavare sells land in la morocha variety of options with and without pool, more inf 04144301822
Has anyone any idea how to do it?