0

I trying to write a php page that will take url values and insert them into an xml file. Any sample files would be of great help.

1
  • What do you mean "url values" - urls? the contents at that url? Commented Jun 18, 2009 at 14:43

1 Answer 1

1

You could do something like the following:

<?php

// get parameters
$parameters = explode ( "&", $_SERVER ['QUERY_STRING'] );

// create new dom document
$doc = new DOMDocument();

// create new root node
$root = $doc->appendChild ( $doc->createELement ( "querystring", "" ));

// iterate all parameters
foreach ( $parameters as $parameter ) {
    // get keypair from parameter
    $keypair = explode ( "=", $parameter );
    // check if we have a key and a value
    if ( count ( $keypair ) == 2 ) {    
        // add new node to xml data
        $root->appendChild ( $doc->createElement( $keypair[0],$keypair[1] ) );
    }   
}

// save XML to variable
$xml = $doc->saveXML();

// echo or output to file...
echo $xml;  

?>

It will take the parameters (key/value pairs) of an URL and adds it to a new XML document. After the saveXML you can do whatever you want with the XML data.

Hope that helps.

Johan.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.