I am trying to extract some information from a csv file. What I want is to extract information only from the lines where this information is from the email and ID.
Previously I had no problems extracting information from csv files via php, however this csv file that I am using has the information in a very particular way.
Here I show part of the contents of the csv file:
As you can see, the information entered is not in a conventional format.
Using this small code:
$file = fopen("mails.csv","rb");
while(feof($file) == false)
{
echo fgets($file). "<br />";
}
fclose($file);
the file is more extensive, has more data. What I have shown is only a small part of the file, used as an example.
What I want to do is extract information from the lines where the radio type input is because there is the email, which is the information that I really want to extract. I have tried with the conventional PHP functions to extract information from csv files but they do not work for me.
they throw me multiple errors and I can not get the information only from the lines that have the emails and save those emails in an array.
Alguna idea que puedan darme para obtener solo las lineas que tienen los inputs radio y extraer de allí el correo electronico de cada linea y guardarlo en un array?
Any help they can give me I would appreciate it.
Assuming that your format never changes (including for the invalid lines that you wish to ignore), the below would work.
Note: I have not tested this code so use this as a pointer and make adjustments as required.
$file = fopen("mails.csv","rb");
while(feof($file) == false){
$contents = fgets($file);
if (substr($contents,0,1) != "#"){
$val = explode(",", $contents);
echo $val[0]. "<br />";
}
}
fclose($file);