PHP Convert XML to JSON Example
This tutorial will give you example of php xml to json. you'll learn php convert xml to json array. This post will give you simple example of php xml to json with attributes. i would like to share with you php xml file to json. Alright, let’s dive into the steps.
In this example, i will give you very simple example of convert xml to json array in php. so here, we will keep one simple example file and convert into php array.
Let's see now:
Add Simple Xml File:
you can create or download simple xml file as like bellow:
now you can see how convert xml to array using bellow code:
$xmlObject = simplexml_load_file('sample.xml');
$jsonData = json_encode($xmlObject, JSON_PRETTY_PRINT);
you will see bellow output:
"name": "Belgian Waffles",
"description": "Two of our famous Belgian Waffles with plenty of real maple syrup",
"name": "Strawberry Belgian Waffles",
"description": "Light Belgian waffles covered with strawberries and whipped cream",
"name": "Berry-Berry Belgian Waffles",
"description": "Light Belgian waffles covered with an assortment of fresh berries and whipped cream",
"name": "French Toast",
"description": "Thick slices made from our homemade sourdough bread",
"name": "Homestyle Breakfast",
"description": "Two eggs, bacon or sausage, toast, and our ever-popular hash browns",
you can check with this code.
i hope it can help you...
- PHP Move File from One Folder to Another Example
- PHP Remove Directory and Files in Directory Example
- PHP Create Directory If It Doesn't Exist Example
- PHP curl post request with parameters and get json response
- PHP - How to implement Google new reCAPTCHA Code Example with Demo?
- How to add CKEditor with image upload using KCFinder in PHP Example Code?
- How to check word exist in string or not in PHP?
- Mediafire PHP file uploading and get link example
- How to convert Object into Array in PHP?
- PHP: How to count files in folder?
- How to remove null values from array in PHP?