wp_check_invalid_utf8 example


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 ) );
    /** * Filters a string cleaned and escaped for output in JavaScript. * * Text passed to esc_js() is stripped of invalid or special characters, * and properly slashed for output. * * @since 2.0.6 * * @param string $safe_text The text after it has been escaped. * @param string $text The text prior to being escaped. */
$use_mb = function_exists( 'mb_convert_encoding' );
    }

    if ( $use_mb ) {
        $encoding = mb_detect_encoding( $input_stringmb_detect_order(), true );
        if ( $encoding ) {
            return mb_convert_encoding( $input_string, 'UTF-8', $encoding );
        } else {
            return mb_convert_encoding( $input_string, 'UTF-8', 'UTF-8' );
        }
    } else {
        return wp_check_invalid_utf8( $input_string, true );
    }
}

/** * Prepares response data to be serialized to JSON. * * This supports the JsonSerializable interface for PHP 5.2-5.3 as well. * * @ignore * @since 4.4.0 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3 * has been dropped. * @access private * * @param mixed $data Native representation. * @return bool|int|float|null|string|array Data ready for `json_encode()`. */
Home | Imprint | This part of the site doesn't use cookies.