- htmlspecialchars_decode: documentation ( source)
- json_encode: documentation ( source)
<?php
$str = 'hello i've got a question';
echo json_encode(
htmlspecialchars_decode($str, ENT_QUOTES),
JSON_HEX_QUOT|JSON_HEX_AMP|JSON_HEX_APOS|JSON_HEX_TAG
);