Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Crawler.php

function Crawler::convertToHtmlEntities

Converts charset to HTML-entities to ensure valid parsing.

3 calls to Crawler::convertToHtmlEntities()
Crawler::addContent in vendor/symfony/dom-crawler/Crawler.php
Adds HTML/XML content.
Crawler::parseHtml5 in vendor/symfony/dom-crawler/Crawler.php
Crawler::parseXhtml in vendor/symfony/dom-crawler/Crawler.php

File

vendor/symfony/dom-crawler/Crawler.php, line 1107

Class

Crawler
Crawler eases navigation of a list of \DOMNode objects.

Namespace

Symfony\Component\DomCrawler

Code

private function convertToHtmlEntities(string $htmlContent, string $charset = 'UTF-8') : string {
    set_error_handler(static fn() => throw new \Exception());
    try {
        return mb_encode_numericentity($htmlContent, [
            0x80,
            0x10ffff,
            0,
            0x1fffff,
        ], $charset);
    } catch (\Exception|\ValueError) {
        try {
            $htmlContent = iconv($charset, 'UTF-8', $htmlContent);
            $htmlContent = mb_encode_numericentity($htmlContent, [
                0x80,
                0x10ffff,
                0,
                0x1fffff,
            ], 'UTF-8');
        } catch (\Exception|\ValueError) {
        }
        return $htmlContent;
    } finally {
        restore_error_handler();
    }
}
RSS feed
Powered by Drupal