PHP使用json stringify对象[关闭]

I have an object in the frontend and need to pass this value to the backend (PHP).

Frontend:

var cfg = {"tooltips":true,"tooltipTemplate":"<div></div>"},
jsonCfg = JSON.stringify(cfg);
$inputConfig.val(jsonCfg);
$form.submit();

Backend:

$config = $_POST['config'];
$json = json_decode($config);
echo $json->tooltips;
echo $json->tooltipTemplate;

The last string gives me only empty value, if I remove the first tag "<", I will get only "div>", but I do not understand how to prevent this behavior, I need any string without filtering or formatting.

Your problem is simply, that <div></div> isn't visible in the browser. If you want to view the correct output, have a look at the page source or use htmlentities to escape the html tags.

$config = $_POST['config'];
$json = json_decode($config);
echo $json->tooltips;
echo htmlentities($json->tooltipTemplate);