Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form to XML Output PHP snippet

Status
Not open for further replies.

BFP

Technical User
May 18, 2000
52
0
0
US
Hi all.

I have a very basic question: how can I take the values in a PHP/HTML form and export them to XML?

For example, suppose I have index.php, which is a job submission form as follows:
Code:
<form id="jobSubmit" name="jobSubmit" method="post" action="">
  <label>Title <input type="text" name="title" /></label> <br />
  <label>Unique Reference # <input type="text" name="referencenumber"></textarea></label> <br />
  <input type="submit" name="btnSubmit" value="Submit" />
</form>
And the required XML output for the job feed is as follows:
Code:
<?xml version="1.0"?>
<source>
	<job>
		<title><![CDATA[Example Job Title]]></title>
		<referencenumber><![CDATA[unique123131]]></referencenumber>
	</job>
</source>
Without worrying about the validations for the time being, how do I output the form data to XML using a PHP script?

[!]Note:[/!] I'd very much like to keep the code generic such that it parses the
Code:
name="X"
and automatically outputs the appropriate XML in the <job>...</job> section.

Thanks in advanced!

BFP
 
Thanks southbeach!

Those two pages saved my butt.

Thank the PHP5 gods for coming up with something so nice to pull this off with ease.

Regards,

BFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top