1

I'm having some trouble when I try to use php's JSON encode function

what I'm doing:

echo json_encode($ppar, JSON_PRETTY_PRINT);

now the variable $ppar is an associative array with a whole bunch of data in it. I can get it to work with out the added parameter, but not with it, and when I looked up on php.net it does say there that the 2nd parameter is valid so I don't get what I'm doing wrong.

this works (except for the fact everything is squished together):

echo json_encode($ppar);

but this:

echo json_encode($ppar, JSON_PRETTY_PRINT);

gives me this error:

Warning: json_encode() expects exactly 1 parameter, 2 given in /home/www/mysite/pp.php on line 10

and the output is null. I've been going to this for reference: http://php.net/manual/en/function.json-encode.php

2 Answers 2

5

You must be running a PHP version prior to 5.3. Since the doc states that is when it was introduced.

Also, JSON_PRETTY_PRINT was added in 5.4. So even though options will work on 5.3, PRETTY_PRINT won't

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

1 Comment

I just noticed it was using 5.2 I was able to get my host to upgrade to 5.3.6 and I no longer get the error message but still a null output. so I'm going to go with the answer that it was introduced in 5.4
3

The "options" parameter (which you set to JSON_PRETTY_PRINT) was added in PHP 5.3.0 - you are probably using a version of PHP older than that.

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.