Guest User

Untitled

a guest
Jun 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <html><head><title>Request Processed</title></head><body>
  2. <?php
  3. class Dog {
  4.     var $name;
  5. }
  6.  
  7. class Adoption
  8. {
  9.     var $dog;
  10.    
  11.     function Display()
  12.     {
  13.         echo $dog->name;
  14.     }
  15. }
  16.  
  17. function save($adoption)
  18. {
  19.     file_put_contents("../adoptions/adoptions.txt", (serialize($adoption)."<!-- E -->"));
  20.  }
  21.  
  22. function loadAdoptions()
  23. {
  24.     $filename = '../adoptions/adoptions.txt';
  25.     if (file_exists($filename))
  26.     {
  27.         $datain = file_get_contents($filename);
  28.         $out = explode("<!-- E -->", $datain);
  29.        
  30.         echo "<br /><u>Retrieved Data</u><br />";
  31.         $count = count($out);
  32.         echo 'Count: '.$count;
  33.        
  34.         for ($i = 0; i < $count; $i++)
  35.         {
  36.             $curAdoption = unserialize($out[i]);
  37.            if (curAdoption)
  38.                 echo $curAdoption->Display();
  39.             else
  40.                 echo 'Error Reading Record.';
  41.             echo '<br />';
  42.         }
  43.  
  44.     }
  45. }
  46.  
  47. $newDog = new Dog();
  48. $newDog->name = "Scruffles";
  49. $newAdoption = new Adoption();
  50. $newAdoption->dog = newDog;
  51. save(newAdoption);
  52. loadAdoptions();
  53. ?>
  54. </body></html>
Add Comment
Please, Sign In to add comment