php method to convert xml to string: first create a php sample file; then define an "array2xml" method; finally use the foreach statement to convert php array to xml string.
Recommended: "PHP Video Tutorial"
php Convert xml string into array and convert array into xml;
1. Convert xml string into php array.
function xmlToArray($xml){ if (file_exists($xml)) { libxml_disable_entity_loader(false); $xml_string = simplexml_load_file($xml,'SimpleXMLElement', LIBXML_NOCDATA); }else{ libxml_disable_entity_loader(true); $xml_string = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA); } $result = json_decode(json_encode($xml_string),true); return $result; }
2. Convert php array to xml string
function array2xml($arr){ $str="<xml>"; foreach ($arr as $key=>$value){ $str.= "<$key>$value</$key>"; } $str.="</xml>"; return $str; }
The above is the detailed content of How to convert xml to string in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version
