All,
Working on a script to convert online search results download files into a MySQL .sql input file. Code is below.
I have no problem scanning the directory with the files and the 1st foreach loop eliminates all non .html files and .html~ edit files.
The "$filr = file($s_path.$fval);" statement correctly loads the file into an array for processing, showing the contents correctly displayed by the print_r statement.
What is not working are the "in_array" statements so only the "get_flat" function is being called. The 3 different files downloaded are either table, div or flat-file display source.
The 3 different functions exist, because"
- The "Table" processing looks for and extracts rows,
- The DIV looks for DIV class to extract rows,
- The FLAT uses each non-blank line to extractBut there are variable blanks in the lines of data and not alignable by column location.
First time for me using in_array and not sure if it is looking for an entire element such as:
Instead of finding 'table' as a substring in the array element.
Code:
$f_ray = scandir ( $s_path );
foreach ($f_ray as $fval) {
// Only read the .html files
$posstr = strpos ($fval, 'html');
$edtfil = strpos ($fval, '~');
if ( ( $posstr < 1 ) || ( $edtfil > 1 ) ) { continue; }
$fil_r[] = $fval;
} // end foreach $f_ray
$o_ray = array();
foreach ($fil_r as $fval) {
echo "File => $fval \n";
$filr = file($s_path.$fval);
print_r ( $filr ); // Works corretly
if ( in_array ( '<table', $filr ) ) { get_table ( $fval, $filr ); }
// if ( in_array ( '<div', $filr ) ) { get_div ( $fval, $filr ); }
get_flat ( $fval, $filr ); // Only function being called
} // end foreach $fil_r
exit;
Hope someone can explain how "in_array" actually works and if it will either need "htmlspecialcharacters" or another approach to find the substrings in the array I'm looking for!
Cheers!
TBNK