PHPBuilder - Formdata to XML



RSS Twitter
Snippets Other

Formdata to XML

by: Florian Schaper
|
September 18, 2002

Version: 1.1

Type: Function

Category: Other

License: GNU Library Public License

Description: This little script build a XML snippet out of a Form request. Sample: <form action="?" method="post"> <input type="text" name="user[firstname]"> <input type="text" name="user[lastname]"> <input type="text" name="user[telephone][home]"> <input type="text" name="user[telephone][work]"> </form> You would start it on with <?php XMLFormdata($_REQUEST); ?> an get <formdata> <user> <firstname>Whatever</firstname> <lastname>Whatever</lastname> <telephone> <home>+49292929292</home> <work>+492343243</work> </telephone> </user> </formdata> Thats it ..



function XMLFormdata( $saFormdata, $iLevel = 1 ) {
	echo (($iLevel==1)?"<formdata>\n":"");
	while( list( $sElement, $sValue ) = each( $saFormdata ) ) {
		echo str_repeat("\t",$iLevel)."<".((is_int($sElement))?"count":"").$sElement.">";
		if( is_array($sValue) ) {
			echo "\n";
			XMLFormdata( $sValue, $iLevel + 1 );
			echo str_repeat("\t",$iLevel);
		} else {
			echo $sValue;
		} // if/else
		echo "</".((is_int($sElement))?"count":"").$sElement.">\n";
	} // while
	echo (($iLevel==1)?"</formdata>\n":"");
} // function XMLFormdata

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Florian Schaper

Comment:



Comment:

(Maximum characters: 1200). You have characters left.