Home > Article > Backend Development > 怎么将"%61"编码成"%61" 怎么将"%61"编码成"%61"
怎么实现上述标题的问题
已解决html转义字符
html_entity_decode();
怎么实现上述标题的问题
已解决html转义字符
html_entity_decode();
<code class="html"> <script type="text/javascript"> var a = 'abcdefg'; a = a.replace(/./g, function(a){ a = '00' + a.charCodeAt(0).toString(16); return '%' + a.substr(a.length - 2); }); alert(a); a = a.replace(/%([0-9a-f]{2})/g, function(a, b){ return String.fromCharCode(parseInt(b, 0x10)); }); alert(a); </script></code>
楼主三番五次改需求是什么意思类?
<code class="php"> <?php function ToHtmlEntities($data){ return sprintf("&#%02s;", ord($data[0])); } function FromHtmlEntities($data){ return chr($data[1]); } $a = '%61'; $a = preg_replace_callback('/./', 'ToHtmlEntities', $a); var_dump($a); $a = preg_replace_callback('/&#(\d+);/', 'FromHtmlEntities', $a); var_dump($a); </code></code>
运行效果:
很好的答案!!