Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php xml to array

public function xmlToArray($xmlstring){
    
  $xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
  $json = json_encode($xml);
  $array = json_decode($json,TRUE);

  return $array;

}
Comment

php read xml file into array

$get = file_get_contents('http://steamcommunity.com/groups/starhawk/memberslistxml/?xml=1.xml');
$arr = simplexml_load_string($get);
print_r($arr);
Comment

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 :: laravel with where has 
Php :: php str to int 
Php :: php echo number with decimal 
Php :: laravel assign class dynamically if condition true 
Php :: laravel loop counter 
Php :: showing php code in browser 
Php :: joomla cache programing clear 
Php :: how to add property to an exsisting object in php 
Php :: delete record using laravel 
Php :: Laravel Validation error message in blade or view 
Php :: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) 
Php :: create view from route laravel 
Php :: turnery expression php 
Php :: laravel limit foreach 
Php :: php add 1 day to current date 
Php :: laravel composer update 
Php :: php counter 
Php :: woocommerce get post meta 
Php :: Excerpt/ get post content 
Php :: Class "AppHttpControllersAdminAuth" not found 
Php :: how send user to 404 page if not exist page in laravel 
Php :: password_hash 
Php :: print array items in php 
Php :: validation error message in laravel 
Php :: how to check using what guard in laravel 8 
Php :: woocommerce profile photo upload 
Php :: php get second last element of array 
Php :: use model from variable laravel 
Php :: php previous page 
Php :: download file php 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =