I appreciate all the help yesterday, it really helped!
I am having some issues on how to take the data that is being split by this correction that was made. I am trying to write this to two separate files, which are us.txt and world.txt and make them identical to the input file, test.txt.
I am getting some strange output on the two output files and cannot figure it out. I have this script, split.php:
<?php
$data = file('test.txt');
// now loop through the array
foreach ($data as $line){
$fields = explode("\t", $line);
// if the array has a US country marker, append the fields to the us.txt file, otherwise put them in the world.txt file
if ($fields[10] == "United States") {
$us_file = fopen("us.txt", "a");
foreach($fields as $cycle) {
fwrite($us_file, $cycle."\t");
}
//fwrite($us_file, "\n");
fclose($us_file);
} else {
$world_file = fopen("world.txt", "a");
foreach($fields as $cycle) {
fwrite($world_file, $cycle."\t");
}
//fwrite($world_file, "\n");
fclose($world_file);
}
}
?>
And I have this script, which was corrected by installer yesterday. How can I incorporate the split.php into the worldreslistings.php. Again I am new to this and am in need of some help. Here is the worldreslistings.php script and the three files.
<?php
$data = file('test.txt');
foreach ($data as $line) {
$fields = explode("\t", $line);
$country = $fields[10];
if ($country == 'United States') {
$ushotels[] = $line;
} else {
$foreignhotels[] = $line;
}
}
foreach ($ushotels as $usdata) {
$fields = explode("\t", $usdata);
foreach ($fields as $key => $field){
echo $key . ' => ' . $field . '<br />';
}
echo '------------<br/>';
}
?>
The input and output files are attached!
Can someone help me out, I would truly appreciate it?
Regards,
Mike