This is called "pretty printed," and SimpleXML does not. If you do a search in Qaru and elsewhere on the Internet, you will find special solutions that do this.
Pretty printing is good for visualization, but I do not recommend saving documents in this format .
If you are still looking for a pretty printer, you can try SimpleDOM asPrettyXML ()
include 'SimpleDOM.php'; $home = simpledom_load_string('<?xml version="1.0" encoding="UTF-8"?> <home><orderList><delivery_cost>0.00</delivery_cost><delivery_surname>TEST</delivery_surname><delivery_postcode>1234</delivery_postcode><status>1</status></orderList></home>'); echo $home->asPrettyXML();
Josh davis
source share