Heim  >  Artikel  >  Backend-Entwicklung  >  怎么将"%61"编码成"%61" 怎么将"%61"编码成"%61"

怎么将"%61"编码成"%61" 怎么将"%61"编码成"%61"

WBOY
WBOYOriginal
2016-06-06 20:21:202020Durchsuche

怎么实现上述标题的问题

已解决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>

运行效果:

怎么将

很好的答案!!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn