wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_specialchars_decode › WordPress Function
Since2.8.0
Deprecatedn/a
› wp_specialchars_decode ( $text, $quote_style = ENT_NOQUOTES )
Parameters: (2) |
|
Returns: |
|
Defined at: |
|
Codex: |
Converts a number of HTML entities into their special characters.
Specifically deals with:&
, </code>, >
, "
, and '
.
$quote_style
can be set to ENT_COMPAT to decode "
entities,
or ENT_QUOTES to do both "
and '
. Default is ENT_NOQUOTES where no quotes are decoded.
Related Functions: wp_specialchars, _wp_specialchars, wp_cache_decr, wp_json_file_decode, wp_cache_close
Source
function wp_specialchars_decode( $text, $quote_style = ENT_NOQUOTES ) { $text = (string) $text; if ( 0 === strlen( $text ) ) { return ''; } // Don't bother if there are no entities - saves a lot of processing. if ( ! str_contains( $text, '&' ) ) { return $text; } // Match the previous behavior of _wp_specialchars() when the $quote_style is not an accepted value. if ( empty( $quote_style ) ) { $quote_style = ENT_NOQUOTES; } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { $quote_style = ENT_QUOTES; } // More complete than get_html_translation_table( HTML_SPECIALCHARS ). $single = array( ''' => '\'', ''' => '\'', ); $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''', ); $double = array( '"' => '"', '"' => '"', '"' => '"', ); $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"', ); $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&', ); $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&', ); if ( ENT_QUOTES === $quote_style ) { $translation = array_merge( $single, $double, $others ); $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); } elseif ( ENT_COMPAT === $quote_style || 'double' === $quote_style ) { $translation = array_merge( $double, $others ); $translation_preg = array_merge( $double_preg, $others_preg ); } elseif ( 'single' === $quote_style ) { $translation = array_merge( $single, $others ); $translation_preg = array_merge( $single_preg, $others_preg ); } elseif ( ENT_NOQUOTES === $quote_style ) { $translation = $others; $translation_preg = $others_preg; } // Remove zero padding on numeric entities. $text = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $text ); // Replace characters according to translation table. return strtr( $text, $translation ); }