answersLogoWhite

0

Php array to xml file

Updated: 8/20/2019
User Avatar

Wiki User

12y ago

Best Answer

If you mean taking an array and making an xml file out of it then you would need to dump the array information into the xml file.

$fp = fopen(filename, "a");

$str = <author>$array['author']</author>

fwrite($fp,$str);

fclose($fp);

that way it will add the contents to the end of thhe file

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Php array to xml file
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How retrieve xml data using php?

Ypu can use file handling function to read XML file_get_contents() file() fopen() Use SimpleXML Library simplexml_load_string - Interprets a string of XML into an object simplexml_load_file - Interprets an XML file into an object


How do you use XML in PHP?

PHP 5 has a XML parser called SimpleXML that you could use.


How do you empty an array in PHP?

To empty an array in PHP you need to use the unset function like shown below: &lt;?php $array = array('hello', 'hi', 'weee'); unset($array); // empty ?&gt;


How do you get a looped array from Flash into PHP?

If you're going from flash to PHP then I would use the Get variables and use a pipe character | (%7C HTML char code) to delimit the array. mysite.com?myvar=8|15|22|88 or mysite.com?myvar=8%7C15%7C22%7C88 If you're going from PHP to flash then use XML. Hope that helps


How do you create a XML file from Scratch?

it is the same way to create xml file by converting into txt you have to use the correct xml syntax ie &lt;xml&gt; this is to denote strat of xml file and this &lt;/xml&gt; denotes end of xml file. You have to use the right xml code or your xml file wont be valid or well formed.


How do you use the XMLReader class in PHP?

Here is an example of how you can grab some information from an xml file using the XMLReader php class. &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;users&gt; &lt;row Id="1" UserName="Paul" /&gt; &lt;row Id="2" UserName="Dave" /&gt; &lt;row Id="3" UserName="Fred" /&gt; &lt;/users&gt; Here is the code to read and grab the information: &lt;?php // load up the xml reader class $reader = new XMLReader(); // xml file to open and read $reader-&gt;open('&lt;url to xml file&gt;'); // loop through the results while ($reader-&gt;read()) { $id = trim($reader-&gt;getAttribute('Id')); // grab the id $username = trim($reader-&gt;getAttribute('UserName')); // grab the username echo "{$id} &gt; {$username}&lt;br /&gt;"; // echo the results } // close the xml file $reader-&gt;close(); ?&gt;


What is the best way to write an array to a file in PHP?

The serialize() function is used to create a storable representation of a variable in PHP.To store an array to a file, you first use the serialize() function to change an array into a string. Save the string in a file using file I/O, so fwrite() or a similar function. When reading it use unserialize() to get the original array again.


How do you see bad XML file?

You can see or view an xml file with a plain text editor like notepad or you can use a dedicated xml editor. With an xml editor you can also validate your xml file which means you can correct any errors in your xml file.


How do you parse very large XML feeds into MySQL with PHP?

You will use an xml parser like simple xml. If you will focus on timeout/connection time out in curl and script time out in php is set to 0(no limit) it will help.


Source code of xml?

there is no source code, xml is not a programming language, its a markup language for which you create your own tags, the basic xml syntax is &lt;xml&gt; to start an xml file, and &lt;/xml&gt; to end the xml file.


Is php a binary file?

No, PHP is text file with .php extension.


What are XML schemas?

an xml schema is a blueprint for your xml file and it dictates what can and cannot be in your xml file. it also is a blueprint as i said and so it outlines the tsructure of your file, the nodes, elements, child, attributes etc