0
file_put_contents(
            $log,
            $this->info['http_code'].", ".
            $this->info['url'].", ".
            '{"12345":"98765","56789":"54321"}'.", ".
            date("Y-m-d H:m:i") .", ".
            PHP_EOL,
            FILE_APPEND
        );

I have a log required to save json into one single csv cell

Because comma (,) it jump to next column's cell.

Anyone know how to store this json data in single cell?

1 Answer 1

2

Try this, Here instead of using file_put_contents you should use fputcsv add also there is no need for PHP_EOL, in this current string next time you call fputcsv then it will automatically comes into your next line.

<?php
$resource=fopen($log, "w+");
fputcsv($resource, 
   array(
      $this->info['http_code'],
      $this->info['url'],
      '{"12345":"98765","56789":"54321"}',
      date("Y-m-d H:m:i")
    )
);
Sign up to request clarification or add additional context in comments.

5 Comments

sry i actually only want json part in single column
@BenjaminW Do you want json to be inserted like cells?
all json in single cell,
Try this, it will put you json in one cell.
just make sure you are using .csv extension for your $log and also put only array of strings as a second argument in fputcsv

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.