How to Read XML File in Laravel?
Now let's see example of how to read xml file in laravel. I will let you know example of laravel read xml file example. We will talk about laravel read xml file. I will learn you how to read xml file in laravel.
You can easily read xml file in laravel 6, laravel 7 and laravel 8 version.
In this example, i will give you very simple example of convert xml to php array in laravel. 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:
Controller Code now you can see how convert xml to array using bellow code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class XMLController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$xmlString = file_get_contents(public_path('sample.xml'));
$xmlObject = simplexml_load_string($xmlString);
$json = json_encode($xmlObject);
$phpArray = json_decode($json, true);
dd($phpArray);
}
}
It will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial