Skip to content

Instantly share code, notes, and snippets.

@kagg-design
Created May 29, 2025 14:57
Show Gist options
  • Save kagg-design/11e520895121d251cfac48b71c244579 to your computer and use it in GitHub Desktop.
Save kagg-design/11e520895121d251cfac48b71c244579 to your computer and use it in GitHub Desktop.
html_entity_decode_deep
/**
* Decode HTML entities in a string.
* Do it cycle to decode all possible entities, including cases like `<`.
*
* @since 1.9.2.3
*
* @param string $html HTML.
* @param int $flags Flags.
* @param string|null $encoding Encoding.
*
* @return string
* @noinspection PhpMissingParamTypeInspection
*/
function wpforms_html_entity_decode_deep( string $html, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, $encoding = null ): string {
do {
$previous_html = $html;
$html = html_entity_decode( $html, $flags, $encoding );
} while ( $html !== $previous_html );
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment