Reputation: 930
htmlentities and json_encode, do I need to use htmlentities if using json_encode which escapes data?
is this enough - json_encode escapes data
echo json_encode( $items );
or do this use htmlentities to escape data:
foreach ( $data as $d ) {
$items[] = htmlentities( $d );
}
echo json_encode( $items );
client-side: JQuery ajax :
$('#textbox').attr( 'value', variable );
Upvotes: 2
Views: 1761
Reputation: 6342
In general, you should not need to use htmlentities()
.
I'm assuming you're using this in the context of an ajax handler? If so, you're biggest concern will be what exactly your calling script is expecting back. If you're handling the JSON response appropriately, there is no need to do anything besides json_encode()
.
Upvotes: 1