Is there a function in php that lets you read a csv and return a string as it is.
I am aware of functions like fgetcsv
etc that reads the csv and returns an array. But I was wondering if there is a way to get the full string as it is.
Asked
Active
Viewed 719 times
-1

Kiran Dash
- 4,816
- 12
- 53
- 84
-
If you mean you want to read *each line* as a string, you can use `file()` ([doc](http://php.net/manual/en/function.file.php)) – utnaf Feb 24 '17 at 11:06
-
@PaulCrovella thanks. didn't know it was such easy. – Kiran Dash Feb 24 '17 at 11:09
2 Answers
1
You must use the file_get_contents function
$data = file_get_contents('http://absoluteUrl');
or
$data = file_get_contents('local url');
Instead, to obtain an array of csv's lines use the file function.

user2342558
- 5,567
- 5
- 33
- 54
1
You could use the file function:
$file = file("somefile.csv")
The you have every line in the variable file:
$file[0] = Firstline, aso.

Nilse
- 140
- 9