Skip to content

Instantly share code, notes, and snippets.

@kagg-design
Created May 29, 2025 14:57
Show Gist options
  • Select an option

  • Save kagg-design/11e520895121d251cfac48b71c244579 to your computer and use it in GitHub Desktop.

Select an option

Save kagg-design/11e520895121d251cfac48b71c244579 to your computer and use it in GitHub Desktop.

Revisions

  1. kagg-design created this gist May 29, 2025.
    22 changes: 22 additions & 0 deletions escape-sanitize.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    /**
    * 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;
    }