Search
 
SCRIPT & CODE EXAMPLE
 

PHP

convert xml file to array php

$xmlfile = file_get_contents($path);
		$ob= simplexml_load_string($xmlfile);
		$json  = json_encode($ob);
		$configData = json_decode($json, true);
Comment

Array to XML Conversion using PHP

<?php
$input_array = array(
    'article' => array(
        array(
            'title' => 'Favorite Star Rating with jQuery',
            'link' => 'https://phppot.com/jquery/dynamic-star-rating-with-php-and-jquery/',
            'description' => 'Doing favorite star rating using jQuery Displays HTML stars.'
        ),
        array(
            'title' => 'PHP RSS Feed Read and List',
            'link' => 'https://phppot.com/php/php-simplexml-parser/',
            'description' => 'simplexml_load_file() function is used for reading data from XML.'
        )
    )
);

$xml = new DOMDocument();

$rootNode = $xml->appendChild($xml->createElement("items"));

foreach ($input_array['article'] as $article) {
    if (! empty($article)) {
        $itemNode = $rootNode->appendChild($xml->createElement('item'));
        foreach ($article as $k => $v) {
            $itemNode->appendChild($xml->createElement($k, $v));
        }
    }
}

$xml->formatOutput = true;

$backup_file_name = 'file_backup_' . time() . '.xml';
$xml->save($backup_file_name);

header('Content-Description: File Transfer');
header('Content-Type: application/xml');
header('Content-Disposition: attachment; filename=' . basename($backup_file_name));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($backup_file_name));
ob_clean();
flush();
readfile($backup_file_name);
exec('rm ' . $backup_file_name);
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php intval 
Php :: import storage laravel 
Php :: do i need to install php after xampp 
Php :: show only 3 initial letter of month in php 
Php :: laravel is route name 
Php :: int to char php 
Php :: count an array in php 
Php :: laravel call controller method from view 
Php :: php html to text 
Php :: php string nach zeichen zerlegen 
Php :: api response in json laravel 
Php :: how to get shop page url in wordpress 
Php :: laravel create request 
Php :: Warning: sprintf(): Too few arguments in /opt/lampp/htdocs/wordpress/wp-admin/includes/class-bulk-upgrader-skin.php on line 152 
Php :: how to calculate percentage profile completion in laravel 
Php :: if session is empty laravel 
Php :: laravel collection pipe 
Php :: array pop php 
Php :: Laravel eloquent restore soft delete 
Php :: openssl encrypt php with key 
Php :: custom rule laravel validation 
Php :: loop foreach laravel with number 
Php :: centos 8 laravel permission denied 
Php :: laravel pagination number of items 
Php :: php image resize 
Php :: php add element to beginning of associative array 
Php :: import local js file laravel 
Php :: php sort array by value 
Php :: laravel set field unique 
Php :: Laravel: Set timestamp column to current timestamp 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =