0

I have a csv file placed at path

#http://thevowapp.com/brandstore/values.csv

$f = fopen("http://thevowapp.com/brandstore/values.csv", "w+");  
if(!f)
{
    echo "Error";
}
$line = fgetcsv($f);
echo json_encode($line);

I am trying to parse it, however the fgetCsv keeps on returning null. What could be the error?

1 Answer 1

1

Problems:

  1. You try to open a remote file with w+ (write) access. Use r for read.
  2. You check f (undefined constant). Use$f`.
  3. You don't loop fgetcsv, so you won't get more than the header line.

Try:

$f = fopen('http://thevowapp.com/brandstore/values.csv', 'r');
if(!$f) {
    echo 'Error';
    exit;
}

$out = array();
while ($line = fgetcsv($f)) {
    $out[] = $line;
}

echo json_encode($out, JSON_PRETTY_PRINT);

Remove the pretty print option when you're happy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.