Search code examples
phpcsvfgetcsv

php read csv data as a string


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.


Solution

  • 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.