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

php laravel api

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Laravel 7 File Upload Via API Example From Scratch

Uploading files via API using postman in laravel. Here, you will learn how to upload files or images via API using postman app or ajax in laravel app.

Top 10 API Security Threats Every API Team Should Know

Learn what are the most important API security threats engineering leaders should be aware of and steps you can take to prevent them

Public ASX100 APIs: The Essential List

The method used for this initial research was to obtain a list of the ASX100 (as of 18 September 2020). Then work through each company looking at the following

Php how to delete multiple rows through checkbox using ajax in laravel

In this article i will let you know to delete multiple rows through checkbox using ajax in laravel and before delete we will give a confirmation message.

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.