2

I have this code here:

case 'resource_list':
        if(file_exists('content.php')){
            include('../ajax/content.php');
        } else {
            die('does not exist');
        }
        $html = render_content_page($array[1],$array[2]);
        $slate = 'info_slate';
        $reply_array = array(
            'html' => $html,
            'slate' => $slate
        );
        echo json_encode($reply_array);
    break;

i have debugged every level right up until json_encode() is called. But the data i receive back in my ajax is nul for the html key. This code is essentially a copy and paste of another case the just calls a function other than render_content_page() but that works perfectly fine.

$reply_array var_exports to:

array (
  'html' => '<ol>
    <li unit="quiz" identifier=""><img src="img/header/notifications.png"/>Fran�ois Vase Volute Krater</li>
    </ol>',
  'slate' => 'info_slate',
)
5
  • 2
    ^thats helpful, what is it then? and php is just annoying..... Commented Jul 14, 2011 at 12:12
  • what php version do you use ? Commented Jul 14, 2011 at 12:12
  • Probably the format or contents of $reply_array. Commented Jul 14, 2011 at 12:13
  • PHP Version 5.3.4, json version 1.2.1 Commented Jul 14, 2011 at 12:17
  • @FraserK php is not annoying, your decision to not use UTF-8 is coming back to bite you. Next time, use UTF-8 everywhere and you won't have these problems. Commented Jul 14, 2011 at 12:18

3 Answers 3

16

My initial thought is that special character in Fran�ois Vase Volute Krater, as json_encode only works with UTF-8 encoded data.

Try UTF-8 encoding it before JSON encoding it like so:

json_encode(utf8_encode("Fran�ois Vase Volute Krater"));
Sign up to request clarification or add additional context in comments.

Comments

5

Maybe problem is with encoding? As manual states, json_encode() works only only with utf8 encoded data:

This function only works with UTF-8 encoded data.

http://php.net/json_encode

Comments

1

As documented, json_encode expects its input text in UTF-8. Most likely, your input (the ç) is not in UTF-8.

Use utf8_encode (if you're currently using ISO-8859-1) or mb_convert_encoding (otherwise) to convert input strings to UTF-8.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.