function process_tests_file($test_file) { echo "Processing tests from {$test_file}\n"; $fh = fopen($test_file, 'r'); if (!$fh) { exit; } while (($line = fgets($fh, 4096)) !== false) { process_line($line); } if (!feof($fh)) { echo "Error: unexpected fgets() fail\n"; exit; } fclose($fh); }
printf("explode trick failed for = %s \n", $line); exit; } //already seen? if (!empty($email) && strcmp($email, "__EMAIL__") != 0 && !in_array($email, $bucket)) { //process $name = isset($tokens[1]) ? $tokens[1] : ""; $title = isset($tokens[2]) ? $tokens[2] : ""; $company = isset($tokens[3]) ? $tokens[3] : ""; $data = sprintf("%s | %s | %s | %s \n", $email, $name, $title, $company); fwrite($fhandle, $data); //update bucket array_push($bucket, $email); } return; } $bucket = array(); $fhandle = fopen("uniq.email", "w"); //files from current directory $all_files = scandir(__DIR__); $ignore = array(".", "..", "uniq.php", "uniq.email"); $ifiles = array_diff($all_files, $ignore); foreach ($ifiles as $ifile) { //get lines from file $lines = file($ifile); foreach ($lines as $line) { process_line($line); } } //release resources fclose($fhandle);
/* * input column(s): var_type * drupal field: variable_type */ $delta = 0; foreach (preg_split("/,\\s*/", $h['var_type']) as $var_type) { if ($var_type) { $tid = var_type_to_tid($var_type); if ($tid) { insert_field($h, "variable_type", array('field_variable_type_tid' => $tid), $delta++); } else { printf(" WARNING: Unknown var_type: '%s'\n", $var_type); } } } } // clear out previously uploaded stuff, and create massupload_data tables to store record of this massupload run if (db_table_exists("massupload_data")) { $result = db_select('massupload_data', 'm')->fields('m', array('tablename', 'where_condition'))->execute(); foreach ($result as $record) { db_query(sprintf("delete from %s where %s\n", $record->{'tablename'}, $record->{'where_condition'})); } db_query("drop table massupload_data"); } db_query("create table massupload_data (tablename varchar(256), where_condition varchar(1024))"); // skip first line of file: fgetcsv($fp); // process remaining lines: while ($h = csv_array_to_hash(fgetcsv($fp))) { process_line($h); }
function process_file($fname) { $lines = file($fname); foreach ($lines as $line) { process_line($line); } }
$next_line = rtrim(get_line($stdin)); } } $pos = strpos($line, "]@ "); if ($pos <= 0) { if (ereg("\\.\\.\\. *@ ", $line)) { $pos = strpos($line, " @ "); } else { $pos = strpos($line, ".@"); } } if ($pos > 0) { process_line(substr($line, 0, $pos + 1), array()); process_line(substr($line, $pos + 1), $tb); } else { process_line($line, $tb); } } echo "</pre>\n"; // Reads the next line from fp, treating normal line breaks and carriage // returns as line breaks function get_line($fp) { static $lines; static $pos; // Get a new set of lines if (!is_array($lines) || $pos >= count($lines)) { $line = fgets($fp, 10 * 1024); // echo "Read line '$line'<br>\n"; $lines = explode("\r", $line); $pos = 0;