Question: how can I run php file on Unix(LF). my code is #!/usr/bin/php $file = fopen(/Users/zhongbojun/PhpstormProjects/partA/Data/input001.a.txt, r); $i = 0; while (!feof($file)) { $line_of_text .= fgets($file);

how can I run php file on Unix(LF).

my code is

#!/usr/bin/php $file = fopen("/Users/zhongbojun/PhpstormProjects/partA/Data/input001.a.txt", "r"); $i = 0; while (!feof($file)) { $line_of_text .= fgets($file); } $members = explode(" ", $line_of_text); fclose($file);

$file1 = fopen("/Users/zhongbojun/PhpstormProjects/partA/Data/input001.b.txt", "r"); $i = 0; while (!feof($file1)) { $line_of_text .= fgets($file1); } $members1 = explode(" ", $line_of_text); fclose($file1); $cartAKey = array(); $cartAValue = array(); $cartBKey = array(); $cartBValue = array();

for ($x = 0; $x < (sizeof($members1)); $x++) {

if ($x< (sizeof($members1)-1)/2){ list ($date , $temperature) = split ('[ ]' , $members1[$x]); // << good array_push($cartAKey, $date); array_push($cartAValue, $temperature);

}else{

list ($date , $temperature) = split ('[ ]' , $members1[$x]); // << good array_push($cartBKey, $date); array_push($cartBValue, $temperature);

}

} $fruit = array_shift($cartAKey); $fruit = array_shift($cartAValue); $fruit = array_shift($cartBKey); $fruit = array_shift($cartBValue);

for ($x = 1;$x <(sizeof($members1)-1)/2;$x++){

if ($cartAKey[$x] == $cartBKey[$x] && $cartBValue[$x] == $cartBValue[$x] ){ unset( $cartAKey[$x] ); // unset 3rd element unset( $cartBKey[$x] ); // unset 3rd element unset( $cartAValue[$x] ); // unset 3rd element unset( $cartBValue[$x] ); // unset 3rd element

} }

$copyAkey = array_values($cartAKey); $copyAvalue = array_values($cartAValue); $copyBkey = array_values($cartBKey); $copyBvalue = array_values($cartBValue);

for ($x = 0;$x<(sizeof($copyAkey));$x++){ if ($copyAkey[$x]==$copyBkey[$x]){ echo "Inconsistent Data (",$copyAkey[$x],"): A: ",$copyAvalue[$x]," B: ",$copyBvalue[$x]; }else{ echo "Missing Data (",$copyAkey[$x]," in data set A but not in B"; echo " "; echo "Missing Data (",$copyBkey[$x]," in data set B but not in A"; echo " ";

} echo " ";

}

But my output for this program

#!/usr/bin/php $file = fopen("/Users/zhongbojun/PhpstormProjects/partA/Data/input001.a.txt", "r"); $i = 0; while (!feof($file)) { $line_of_text .= fgets($file); } $members = explode(" ", $line_of_text); fclose($file);

$file1 = fopen("/Users/zhongbojun/PhpstormProjects/partA/Data/input001.b.txt", "r"); $i = 0; while (!feof($file1)) { $line_of_text .= fgets($file1); } $members1 = explode(" ", $line_of_text); fclose($file1); $cartAKey = array(); $cartAValue = array(); $cartBKey = array(); $cartBValue = array();

for ($x = 0; $x < (sizeof($members1)); $x++) {

if ($x< (sizeof($members1)-1)/2){ list ($date , $temperature) = split ('[ ]' , $members1[$x]); // << good array_push($cartAKey, $date); array_push($cartAValue, $temperature);

}else{

list ($date , $temperature) = split ('[ ]' , $members1[$x]); // << good array_push($cartBKey, $date); array_push($cartBValue, $temperature);

}

} $fruit = array_shift($cartAKey); $fruit = array_shift($cartAValue); $fruit = array_shift($cartBKey); $fruit = array_shift($cartBValue);

for ($x = 1;$x <(sizeof($members1)-1)/2;$x++){

if ($cartAKey[$x] == $cartBKey[$x] && $cartBValue[$x] == $cartBValue[$x] ){ unset( $cartAKey[$x] ); // unset 3rd element unset( $cartBKey[$x] ); // unset 3rd element unset( $cartAValue[$x] ); // unset 3rd element unset( $cartBValue[$x] ); // unset 3rd element

} }

$copyAkey = array_values($cartAKey); $copyAvalue = array_values($cartAValue); $copyBkey = array_values($cartBKey); $copyBvalue = array_values($cartBValue);

for ($x = 0;$x<(sizeof($copyAkey));$x++){ if ($copyAkey[$x]==$copyBkey[$x]){ echo "Inconsistent Data (",$copyAkey[$x],"): A: ",$copyAvalue[$x]," B: ",$copyBvalue[$x]; }else{ echo "Missing Data (",$copyAkey[$x]," in data set A but not in B"; echo " "; echo "Missing Data (",$copyBkey[$x]," in data set B but not in A"; echo " ";

} echo " ";

}

The errors happened in codes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!