Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php xml problem

Posted on 2006-11-25
3
Medium Priority
?
216 Views
Last Modified: 2013-12-12
I have the following code:

<?php
      //includes
      include('conf.php');
      
      $connection = mysql_connect($host, $user, $pass)
      or die ('Unable to connect!');

      function add_to_queue( $func, $arg )
      {
            global $db;
            
            $dom = new DomDocument();
            $root = $dom->createElement( "arguments" );
            foreach( $args as $argtext )
            {
                  $arg = $dom->createElement( "argument" );
                  $arg->appendChild( $dom->createTextNode( $artext ) );
                  $root->appendChild( $arg );
            }            
            $dom->appendChild( $root );
            
            $sth = $db->prepare( "INSERT INTO queue VALUES ( 0, ?, ? )" );
            $db->execute( $sth, array( $func, $dom->saveXML() ) );
      }

      function run_queue()
      {
            global $db;
            
            $delsth = $db->prepare( "DELETE FROM queue VALUES ( 0, ?, ? )" );
            
            $res = $db->query( "SELECT id, func, args FROM queue" );
            while( $res->fetchInto($row) )
            {
                  $id = $row[0];
                  $func = $row[1];
                  $argxml = $row[2];
                  
                  $dom = new DomDocument();
                  $dom->loadXML( $argxml );
                  $arg = array();
                  foreach( $dom->getElementsByTagName( "argument" ) as $node )
                  {
                        $arg []= $node->nodeValue;
                  }
                  
                  call_user_func_array( $func, $args );
                  
                  $db->execute( $delsth, array( $id ) );
            }
      }
?>

I am using a server that is running php version 4.4.2 and I need to get this script to work... it is obviously a php 5 script (DomDocumet();).  How would I convert it?
0
Comment
Question by:gishdog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 18013852
Have a look at PHP4 XML functions http://www.php.net/manual/en/ref.domxml.php
0
 
LVL 8

Accepted Solution

by:
John Kawakami earned 2000 total points
ID: 18014160
How important is it that the $arg be stored as XML?

If it's not important at all, use serialize($arg) to convert the PHP values into a string, and unserialize($str) to convert the string back into an array of values.

If using XML is important, then this won't help.  

The XML looks gratuitous to me :-)

     function add_to_queue( $func, $arg )
     {
          global $db;          
          $sth = $db->prepare( "INSERT INTO queue VALUES ( 0, ?, ? )" );
          $db->execute( $sth, array( $func, serialize($arg) ) );
     }

     function run_queue()
     {
          global $db;
         
          $delsth = $db->prepare( "DELETE FROM queue VALUES ( 0, ?, ? )" );
         
          $res = $db->query( "SELECT id, func, args FROM queue" );
          while( $res->fetchInto($row) )
          {
               call_user_func_array( $row[1],  unserialize($row[2]) );
               $db->execute( $delsth, array( $row[0] ) );
          }
     }
0
 

Author Comment

by:gishdog
ID: 18014398
Yea... After sleeping on it the xml does seem like overkill... I think I'm going to go for the serialize route... thanks for the help.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question