I have a csv-file (semi-colon-seperated) and get it into php like this;
$file_handle = fopen("data.csv", "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 0, ";");
print $line_of_text[0] . $line_of_text[1] ((...etc));
}
fclose($file_handle);
I would like to print/echo all rows containing a certain keyword. I am hoping I could pop in something like:
"SELECT file_handle WHERE line_of_text[3] LIKE '%keyword'"
but, as far as I can tell, the WHERE clause is mySQL only?
So any nice tips on this are most welcome :-)
edit:
My csv looks something like this:
ID; Date; First name; Last name; Value (integer); Value (integer)
94; 15-11-14; John; Smith; 329,00; 500
95; 15-11-15; James; Jones; 211,00; 600
try filtering the array $line_of_text with in_array
function
<?php
$row = 1;
$your_value_to_search = 'your_value';
if (($handle = fopen("data.csv", "r")) !== FALSE) {
while (($line_of_text = fgetcsv($handle, 1000, ",")) !== FALSE) {
if (in_array( $your_value_to_search, $line_of_text)) {
$num = count($line_of_text);
for ($c=0; $c < $num; $c++) {
echo $line_of_text[$c] . "<br />
";
}
}
$row++;
}
fclose($handle);
}
?>