Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP json_encode() making data null

Tags:

json

jquery

php

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',
)
like image 409
FraserK Avatar asked Jul 01 '26 19:07

FraserK


1 Answers

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"));
like image 186
AlienWebguy Avatar answered Jul 03 '26 08:07

AlienWebguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!