Definition:
function esc_js( $text ) {}
Escape single quotes, htmlspecialchar " < > &, and fix line endings.
Escapes text strings for echoing in JS. It is intended to be used for inline JS (in a tag attribute, for example onclick="…"). Note that the strings have to be in single quotes. The filter ‘js_escape’ is also applied here.
Parameters
- string $text: The text to be escaped.
Return values
returns:Escaped text.
Defined filters
- js_escape
apply_filters( 'js_escape', $safe_text, $text )
Source code
function esc_js( $text ) { $safe_text = wp_check_invalid_utf8( $text ); $safe_text = _wp_specialchars( $safe_text, ENT_COMPAT ); $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); $safe_text = str_replace( "\r", '', $safe_text ); $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); return apply_filters( 'js_escape', $safe_text, $text ); }
1036
No comments yet... Be the first to leave a reply!