Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the spinupwp domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /sites/coreysalzano.com/files/wp-includes/functions.php on line 6121
PHP4 Friendly htmlspecialchars_decode – Corey Salzano

PHP4 Friendly htmlspecialchars_decode

I needed to use the PHP function htmlspecialchars_decode( ) for a WordPress widget I am making. This function is built into PHP versions 5.1.0 and greater and is used to convert special HTML entities to characters. As defined, htmlspecialchars_decode( ) is the opposite of htmlspecialchars( ). Someone named Thomas commented on the PHP man page to point out a flaw in the definition. He also provides some code, which I have only modified slightly below to check function_exists( ).


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);
    }
}

 


Comments

2 responses to “PHP4 Friendly htmlspecialchars_decode”

  1. This is not working for ‘ and ’ ?

  2. Ken:

     

    I am not sure what you mean. The purpose of this function is to handle special characters in URLs, not plain text.