我在使用json_encode解析HTML字符串时遇到了问题。例如,我的字符串:
<h5>Name</h5>
当出现">"时,我的json格式就被破坏了。我在PHP中找到了解决方法:
json_encode('ARRAY', 'JSON_HEX_QUOT | JSON_HEX_TAG')
但是我需要在TWIG中执行此操作,这个方式在TWIG中无法正常运行。我遇到了错误:
An exception has been thrown during the rendering of a template ("Warning: json_encode() expects parameter 2 to be long, string given") in src/Cloud/ApplicationBundle/Resources/views/Filters/tab.html.twig at line 1.