5
5

More than 5 years have passed since last update.

htmlspecialchars_decodeをPHP4上で動作させなければならない場合の対処方法

Posted at

htmlspecialchars_decode について。

突然のエラー、、
原因は「htmlspecialchars_decode」関数がPHP4環境では動作しないとのこと。。

そのため、似たような処理をPHP4上で実現させるための対処方法を調べました。

if ( !function_exists('htmlspecialchars_decode') ){
    function htmlspecialchars_decode($string,$style=ENT_COMPAT)
    {
        $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style));
        if($style === ENT_QUOTES){ $translation['''] = '\''; }
        return strtr($string,$translation);
    }
}

このコードを追記するだけで無事、エラーは消え、デコードもされていました。

フォームに入力した値も正常に変換されていたので問題なく動いている・・。

http://www.umbrellastudio.com/web-development/php4-friendly-htmlspecialchars_decode/ より

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5