PHP that display prompt messages
ExamB/ExamB.php
<?php // get user file $filename = $_REQUEST['filepath'] ; $validate = true ; $x = array(); $y = array(); // var to get Point variable $X_avg = $X_sum = 0 ; $Y_avg = $Y_sum = 0 ; if (!file_exists($filename)){ echo "Please correct file path." ; } else // >>>>>>>>>>>>>>>>>> HERER <<<<<<<<<<<<<<<<<<<< // { // load code file $Points = file_get_contents($filename) ; // get code lines $Points_lines = explode("\n", $Points); // validate empty line foreach ( $Points_lines as $line) { if(strlen($line) == 0 ) { $validate = false ; $validate_message = "Empty Line" ; } } // validate pairs & Numbers if($validate) foreach ( $Points_lines as $line) { $Pairs = explode(",", $line); if(strlen($Pairs[0]) == 0 || strlen($Pairs[1]) == 0 ) { $validate = false ; $validate_message = "Pairs Mismatching " ; break; } else { if(is_numeric($Pairs[0]) && is_numeric($Pairs[1]) ) { $validate = true ; } else { $validate = false ; $validate_message = "Only numeric accepted" ; break ; } } } // validate >= 0 if($validate) foreach ( $Points_lines as $line) { $Pairs = explode(",", $line); if(($Pairs[0] > 0 ) && ($Pairs[1] > 0) ) { $validate = true ; } else { $validate = false ; $validate_message = "Only accepted value of larger than zero" ; break ; } } if(!$validate) { echo "Validation Error , >> $validate_message << " ; exit(); } // >>>>>>>>>>>>>>>>>>> get N value <<<<<<<<<<<<<<<< $n = count($Points_lines); $i=1 ; foreach ( $Points_lines as $line) { // X values $Pairs = explode(",", $line); $x[$i-1] = $Pairs[0]; // Y values $y[$i-1] = $Pairs[1]; // get avg for X & Y arrays $X_sum += $x[$i-1] ; $Y_sum += $y[$i-1] ; // X^2 - Y^2 $X_2 += ($x[$i-1] * $x[$i-1]); $Y_2 += ($y[$i-1] * $y[$i-1]); // X*Y $X_in_Y += ($x[$i-1] * $y[$i-1]) ; $i++ ; } print_r($x); echo "<hr>"; print_r($y); echo "<hr>"; // X avg , Y avg $X_avg = $X_sum/$n ; $Y_avg = $Y_sum/$n ; // X avg^2 $Xavgintwo = $X_avg*$X_avg; //B One $BOne = (($X_in_Y-($n*$X_avg*$Y_avg))/($X_2-($n*$Xavgintwo))); echo "B One : $BOne <br>"; echo "<hr>"; //B Zero $BZero = ($Y_avg-($BOne*$X_avg)); echo "B Zero : $BZero <br>"; echo "<hr>"; //R x y $RTwo_1 = (($n*$X_in_Y)-($X_sum*$Y_sum)); $RTwo_2_1 = (($n*$X_2)-($X_sum*$X_sum)); $RTwo_2_2 = (($n*$Y_2)-($Y_sum*$Y_sum)); $RTwoBottomSqrt = sqrt (($RTwo_2_1)*($RTwo_2_2)); $RTwoxy = ($RTwo_1/$RTwoBottomSqrt); echo "R x y : $RTwoxy <br>"; //R Two $RTwo = $RTwoxy * $RTwoxy; echo "R Two : $RTwo <br>"; } ?>
__MACOSX/ExamB/._ExamB.php
ExamB/HomeB.html
Insert path location of your file:ExamB/test.txt
16,235 51,337 122,285 72,344