_wp_json_convert_string() – Converts a string to UTF-8, so that it can be safely encoded to JSON.

You appear to be a bot. Output may be restricted

Description

Converts a string to UTF-8, so that it can be safely encoded to JSON.

Usage

$string = _wp_json_convert_string( $input_string );

Parameters

$input_string
( string ) required – The string which is to be converted.

Returns

string The checked string.

Source

File name: wordpress/wp-includes/functions.php


Lines:

1 to 18 of 18
function _wp_json_convert_string( $input_string ) {
  static $use_mb = null;
  if ( is_null( $use_mb ) ) {
    $use_mb = function_exists( 'mb_convert_encoding' );
  }

  if ( $use_mb ) {
    $encoding = mb_detect_encoding( $input_string, mb_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 );
  }
}
 

 View on GitHub View on Trac