Codex对这两种功能的描述:
wp_specialchars
: 将许多特殊字符转换为其HTML实体。具体涉及:&<;,>,“、和”。
wp_specialchars_decode
: 将许多HTML实体转换为它们的特殊字符。
根据
http://codex.wordpress.org/Function_Reference/wp_specialchars
自WordPress 2.8.0起,此函数已被弃用。请改用esc\\U html。
您不希望在html输出中有特殊字符,因此不希望使用wp_specialchars_decode
为此。
有一个特殊的函数esc_js()
你应该考虑的
http://codex.wordpress.org/Function_Reference/esc_js
此函数的源代码可在此处找到:
http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/formatting.php#L2641
/**
2641 * Escape single quotes, htmlspecialchar " < > &, and fix line endings.
2642 *
2643 * Escapes text strings for echoing in JS. It is intended to be used for inline JS
2644 * (in a tag attribute, for example onclick="..."). Note that the strings have to
2645 * be in single quotes. The filter \'js_escape\' is also applied here.
2646 *
2647 * @since 2.8.0
2648 *
2649 * @param string $text The text to be escaped.
2650 * @return string Escaped text.
2651 */
2652 function esc_js( $text ) {
2653 $safe_text = wp_check_invalid_utf8( $text );
2654 $safe_text = _wp_specialchars( $safe_text, ENT_COMPAT );
2655 $safe_text = preg_replace( \'/&#(x)?0*(?(1)27|39);?/i\', "\'", stripslashes( $safe_text ) );
2656 $safe_text = str_replace( "\\r", \'\', $safe_text );
2657 $safe_text = str_replace( "\\n", \'\\\\n\', addslashes( $safe_text ) );
2658 return apply_filters( \'js_escape\', $safe_text, $text );
2659 }
下面是一个很好的数据验证概述:
http://codex.wordpress.org/Data_Validation