php data filtering and count

0

I have a web app where I generate graphs, but I would like to filter data and make a bundle, I have only one data in a bd, so I already exported it and to avoid q it was slow I was thinking of reading from csv but I need to filter the data somebody knows how I can do ex:

csv

Nome, profissão, Idade,Sexo ,Nacionalidade , quantidade
jose , trolha,10,M,nacional,10
jose , trolha,10,M,nacional,10
jose , trolhaassda1,10,M,nacional,10
jose , trolha1dsds,10,M,nacional,10
jose , trolh1111,10,M,nacional,10
jose , trolhadasdas,10,M,nacional,10

I wanted to see only the troll. it is possible

output Name, profession, Age, Sex, Nationality, quantity Jose Trolley, 10 M National 10 jose, trolha, 10, M, national, 10

    
asked by anonymous 04.10.2016 / 22:19

1 answer

0

The most performative way to do this would be to use a database and filter the data you need.

In the case of using a file, you can use a regex to extract the data you need or read the whole file and use the PHP strpos function.

Ex. in MySQL:

SELECT * FROM tabela_csv WHERE profissao LIKE '%trolha%';

Ex. in PHP using RegEx:

$regex = "(.*?)\ ,\ (.*?)trolha(.*?),(.*?),(.*?),(.*?),(.*?)\n";
preg_match_all($regex, $csvContent, $matches);
    
05.10.2016 / 16:40