Article 5T7Y9 PHP IN_Array function

PHP IN_Array function

by
TBotNik
from LinuxQuestions.org on (#5T7Y9)
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"
  1. The "Table" processing looks for and extracts rows,
  2. The DIV looks for DIV class to extract rows,
  3. The FLAT uses each non-blank line to extract
    • Name,
    • URL,
    • City,
    • State.
    But 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:

Code:$ray[1] = 'table'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!

TBNKlatest?d=yIl2AUoC8zA latest?i=J_7PS5NTBJw:-DDpvjZOqc4:F7zBnMy latest?i=J_7PS5NTBJw:-DDpvjZOqc4:V_sGLiP latest?d=qj6IDK7rITs latest?i=J_7PS5NTBJw:-DDpvjZOqc4:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments