Advertisement
imoda

fetchXML

Sep 12th, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?
  2.  
  3.     function fetchXML($params = false) {
  4.        
  5.         // Are we overriding the default XML path calculation?
  6.         if ($params !== false) {
  7.            
  8.             $address = $params;
  9.         }
  10.         // No? Didn't think so
  11.         else {
  12.            
  13.             $address = substr($_SERVER['SCRIPT_NAME'], +1, -4);
  14.            
  15.             if (isset($_GET['category'])) {
  16.                
  17.                 $address .= "/" . $_GET['category'];
  18.                
  19.                 if (isset($_GET['subcategory'])) {
  20.                    
  21.                     $address .= "/" . $_GET['subcategory'];
  22.                 }
  23.                
  24.                 if (isset($_GET['page'])) {
  25.                    
  26.                     $address .= "/" . $_GET['page'];
  27.                 }
  28.                 else {
  29.                    
  30.                     $address .= "/" . (isset($_GET['subcategory']) ? $_GET['subcategory'] : $_GET['category']) . "_index";
  31.                 }
  32.             }
  33.             else if (isset($_GET['page'])) {
  34.                    
  35.                 $address .= "/" . $_GET['page'];
  36.             }
  37.             else {
  38.                
  39.                 $address .= "/" . $address . "_index";
  40.             }
  41.         }
  42.        
  43.         $address = "xml/" . $address . ".xml";
  44.        
  45.         //echo $address;        //testing porpoises
  46.        
  47.         if (file_exists($address)) {
  48.            
  49.             $output = simplexml_load_file($address) or die("Error loading XML");
  50.         }
  51.         else {
  52.            
  53.             $output = false;
  54.         }
  55.            
  56.         return $output;
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement