topical media & game development

talk show tell print

basic-ajax-07-GetStocksList.php / php



  <?php   
                   dom = new DomDocument('1.0');
          dom->load('stocks.xml');
                  root = dom->lastChild;
          srand(time());
          foreach (root->childNodes As child)
          {
              RandomNumber = (rand()%100);
              if (child->nodeType == 1) 
              {
                                  foreach (child->childNodes As subchild)
                                  {
                  if (subchild->nodeName == "price")
                  {
                      value = subchild->textContent;
                      RandomPrice = (rand()%value);
                      RandomPrice = RandomPrice / 10;
                      
                      direction = "";
                      if ((RandomNumber % 2) == 1)
                      {
                          direction = "Down";
                          value = value - RandomPrice;
                         
                      }
                      else
                      {
                           direction = "Up";
                           value = value + RandomPrice;
                      }
                          
                                               
                                               textNode = dom->createTextNode(value);
                                               subchild->nodeValue = "";
                           newchild = subchild->appendChild(textNode);
                  }
  
                      if (subchild->nodeName == "direction")
                  {
                                                   textNode = dom->createTextNode(direction);
                                                   subchild->nodeValue = "";
                           newchild = subchild->appendChild(textNode);
                  }
                          }
              }
          }
      dom->save('stocks.xml');
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.