John Davidson

php - How can I make a simplexml_load_file readable?

0 comments
Message:


Hello everyone I'm using simplexml_load_file to load a url so I can get a catalog from a another company. How can I make it so its readable like this:


Catalog website


and not like this


Catalog in php



The catalog that's on the website is the url that I use in my code, so e.g. https://USERNAME:[email protected]/generator/catalog/xml - I can't share the company's real address.


this is how I get the catalog from the company


$url = "https://USERNAME:[email protected]/generator/catalog/xml";
$xml = simplexml_load_file($url);
foreach ($xml->PRODUCT as $product) {
print_r($product);
}


My Answer:
To make the output of simplexml_load_file more readable, you can use the print_r function with the second parameter set to true. This will format the output in a more human-readable way. Here's an example:

php
$url = "https://USERNAME:[email protected]/generator/catalog/xml";
$xml = simplexml_load_file($url);
foreach ($xml->PRODUCT as $product) {
print_r($product, true);
}


This will display the XML data in a more structured and readable format. You can also use var_dump instead of print_r for more detailed information about the XML data.

Rate this post

3 of 5 based on 7987 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us