2

htmlentities 和 json_encode,如果使用转义数据的 json_encode,我是否需要使用 htmlentities?

这够了吗 - json_encode 转义数据

    echo json_encode( $items );

或者这样做使用 htmlentities 来转义数据:

    foreach ( $data as $d ) {

        $items[] = htmlentities( $d );

    }

    echo json_encode( $items );

客户端:JQuery ajax:

    $('#textbox').attr( 'value', variable ); 
4

1 回答 1

1

通常,您不需要使用htmlentities().

我假设您在 ajax 处理程序的上下文中使用它?如果是这样,您最关心的将是您的调用脚本到底期待什么。如果您正在适当地处理 JSON 响应,那么除了json_encode().

于 2013-02-22T18:59:41.317 回答