Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( 0 == filesize($filepath.$filename)) {
- $error_message = "file is empty!";
- } else {
- //reading first entry
- $handle = fopen($filepath.$filename, "r");
- if ($handle) {
- $obj_array = array();
- $file_contents = "";
- do {
- // process the line read.
- do {
- $line = trim(fgets($handle));
- if ($line == false) {
- echo "line equals false - file has ended!";
- $fileHasEnded = true;
- break;
- }
- } while ($line == "");
- if (isset($fileHasEnded) && $fileHasEnded) {
- $error_message = "file has ended!";
- break;
- }
- if ($line=="Season") {
- $line = trim(fgets($handle));
- if ($line == false)
- break;
- if (preg_match("/^[0-9a-z]{3,4}$/i", $line)) {
- if ($line=="SRoc" || $line=="S1E" || preg_match("/^S0[0-9]{1}$/", $line)) {
- $Season = $line;
- //$season = $line;
- $line = trim(fgets($handle));
- if ($line == false)
- break;
- if ($line=="RaceType") {
- $line = trim(fgets($handle));
- if ($line == false)
- break;
- if (preg_match("/^[a-z0-9 ]{5,30}$/i", $line)) {
- $RaceType = $line;
- //$raceType = $line;
- $line = trim(fgets($handle));
- if ($line == false)
- break;
- if ($line =="Account") {
- $line = trim(fgets($handle));
- if ($line == false)
- break;
- if (preg_match("/^[a-z0-9_]{3,30}$/i", $line)) {
- $Account = $line;
- $line = trim(fgets($handle));
- if ($line == false)
- break;
- if ($line=="Points") {
- $line = trim(fgets($handle));
- if ($line == false)
- break;
- if (preg_match("/^[0-9]{1,10}$/", $line)) {
- $Points = $line;
- //$obj_array[] = $obj;
- $obj_array[] = (object) array('Season' => $Season, 'RaceType' => $RaceType, 'Account'=>$Account,'Points' => $Points);
- echo "added new entry!";
- } else {
- $error_message = "Points value '" . $line . "' is not allowed! You can only use digits. From 1 to 10 digits long.";
- }
- } else {
- $fileReadStatus = false;
- $error_message = "Unknown type value found! Expected: Points, Found: " . $line;
- break;
- }
- } else {
- $error_message = "Account value '" . $line . "' is not allowed! You can only use '_', english alphabet and digits. From 3 to 30 symbols long.";
- }
- } else {
- $fileReadStatus = false;
- $error_message = "Unknown type value found! Expected: Account, Found: " . $line;
- break;
- }
- } else {
- $error_message = "Race type value '" . $line . "' is not allowed! You can only use whitespace, english alphabet and digits. From 5 to 30 symbols long.";
- }
- } else {
- $fileReadStatus = false;
- $error_message = "Unknown type value found! Expected: RaceType, Found: " . $line;
- break;
- }
- } else {
- $error_message = "Season value is wrong! Unknown value found: " . $line;
- }
- } else {
- $error_message = "Season value is wrong! Unknown value found: " . $line;
- }
- } else {
- $fileReadStatus = false;
- $error_message = "Unknown type value found! Expected: Season, Found: " . $line;
- break;
- }
- }
- while (true);
- if ($fileReadStatus) {
- $file_contents = "";
- foreach ($obj_array as $object) {
- $object_to_string = $object->Season . "<br/>";
- $object_to_string = $object_to_string . $object->RaceType . "<br/>";
- $object_to_string = $object_to_string . $object->Account . "<br/>";
- $object_to_string = $object_to_string . $object->Points . "<br/>";
- $file_contents = $file_contents . $object_to_string;
- }
- }
- } else
- $error_message = "There was an error while opening file!";
- fclose($handle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement