Skip to main content

Posts

Showing posts with the label XML

How to Create and Save XML File using PHP

XML stands for Extensible Markup Language which is used for store and transport data. Some web project needs to store products, user, or other information in the XML file. In those projects, you should need to generate XML data or convert PHP array to XML , then create and save the XML file using PHP. Also, XML format is commonly used in sitemap of the website. In this tutorial, we’ll show the simple way to generate XML file using PHP. You can use XML DOM Parser to process XML document in PHP. Also, using saveXml() and save() method you’ll be able to output XML document to the browser and save XML document as a file. The saveXml() function puts internal XML document into a string. The save() function puts internal XML document into a file. The following example PHP code will create XML sitemap and save XML file into the xml/ directory. $xmlString = '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema...

Convert array to XML in PHP

Home   »   PHP   »   Convert array to XML in PHP Many times we need store the data as a XML into the database or into the file for later use. For fulfil this need, we will need to convert the data to XML and save the XML file. In this tutorial we will discuss, how to create XML from array in PHP. We have created a simple script for convert PHP array to XML. You can easily generate XML file from PHP array and save the XML file. You can convert all types of array like Associative array or Multidimensional arrays. PHP Array: At first we will store the users data into a variable ( $users_array ). $users_array = array( "total_users" => 3, "users" => array( array( "id" => 1, "name" => "Smith", "address" => array( "country" => "United Kingdom", "city...