php explode multi line text in text file

php explode multi line text in text file

i have a text file and the data inside is:

i have a text file and the data inside is:

john,male,20,200,174
joe,male,24,157,166
bea,female,18,153,160
edd,male,30,180,180

I am using laravel and so i have the folder containing this text file in storage/app/upload. In my controller this is my code:

public function readfile() 
    {
        $file = Storage::get('upload/test.txt');        
        $array = explode(',', $file);
        print_r($array);
    }

the output is:

Array
(
    [0] => john
    [1] => male
    [2] => 20
    [3] => 200
    [4] => 174
joe
    [5] => male
    [6] => 24
    [7] => 157
    [8] => 166
bea
    [9] => female
    [10] => 18
    [11] => 153
    [12] => 160
edd
    [13] => male
    [14] => 30
    [15] => 180
    [16] => 180
)

what i NEED to happen is this:

Array
(
     [0] => john,male,20,200,174
     [1] => joe,male,24,157,166
     [2] => bea,female,18,153,160
     [3] => edd,male,30,180,180
)

I am still new to this and i hope someone can help me. Thanks in advance

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Integrate PHP Laravel 5.8 APIs in Angular 7

For PHP Laravel APIs to integrate in Angular 7, we have to write APIs in api.php file in Laravel which is in the routes folder in Laravel project structure. For the sake of this article, we are using example of User API.

Laravel API Response - Simple Laravel API response wrapper

Laravel API Response is a good package that we can use to create API responses easily.

How to Creat an API in Laravel with Passport

You will be learning how to build an API in Laravel Passport and how to generate a token for a user. This token is used to authenticate the user.