Skip to content

Instantly share code, notes, and snippets.

@zgurya
Created April 22, 2016 21:24
Show Gist options
  • Save zgurya/e98ee3e3ea1ad22db22c9ef4e4dc1521 to your computer and use it in GitHub Desktop.
Save zgurya/e98ee3e3ea1ad22db22c9ef4e4dc1521 to your computer and use it in GitHub Desktop.
Get sum data from rectangle data
<!DOCTYPE html>
<html>
<head>
<title>Get file data</title>
<meta charset="UTF-8">
</head>
<body>
<?php if(isset($_POST['file_url']) || !empty($_POST['file_url'])):?>
<?php
$data=0;
$file_url=$_POST['file_url'];
foreach (file($file_url) as $line_num => $line) {
$line_arr=explode(' ',htmlspecialchars($line));
if(count($line_arr)<=2){
$data+=$line_arr[0];
}else{
$data+=$line_arr[count($line_arr)-2];
}
}
echo 'Sum is '.$data.'</br>';
?>
<a href="">Try new file</a>
<?php else:?>
<form action="" method="post" name="set_file_url">
<input type="text" name="file_url" id="file" size="30">
<input type="submit" value="Get data">
</form>
<?php endif;?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment