사이트 내 전체검색
PHP
' & #39; htmlspecialchars_decode 변환
로빈아빠
https://cmd.kr/php/835 URL이 복사되었습니다.

본문

$str="' 최고얼짱은 한국인! '";

$str=htmlspecialchars_decode($str, ENT_QUOTES);
echo "<XMP>$str\n";
echo "<XMP>",htmlspecialchars_decode($str);
exit;


<?php
    var_dump(get_html_translation_table(HTML_SPECIALCHARS,ENT_QUOTES));
    var_dump(htmlspecialchars('\'',ENT_QUOTES));
?>
--------------------

  Output:
--------------------
array
  '"' => '&quot;'
  ''' => '&#39;'
  '<' => '<'
  '>' => '>'
  '&' => '&amp;'

'&#039;'
--------------------

This comment now is not to report this bug again (though I really believe it is one), but to complete the example and warn people of this pitfall.

To make sure your htmlspecialchars_decode fake for PHP4 works, you should do something like this:

<?php
    function htmlspecialchars_decode($string,$style=ENT_COMPAT)
    {
        $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style));
        if($style === ENT_QUOTES){ $translation['&#039;'] = '\''; }
        return strtr($string,$translation);
    }
?>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (3/18P)

Search

Copyright © Cmd 명령어 3.144.28.65