You are here

public function Crawler::addContent in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dom-crawler/Crawler.php \Symfony\Component\DomCrawler\Crawler::addContent()

Adds HTML/XML content.

If the charset is not set via the content type, it is assumed to be ISO-8859-1, which is the default charset defined by the HTTP 1.1 specification.

Parameters

string $content A string to parse as HTML/XML:

null|string $type The content type of the string:

1 call to Crawler::addContent()
Crawler::add in vendor/symfony/dom-crawler/Crawler.php
Adds a node to the current list of nodes.

File

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

Class

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

Namespace

Symfony\Component\DomCrawler

Code

public function addContent($content, $type = null) {
  if (empty($type)) {
    $type = 0 === strpos($content, '<?xml') ? 'application/xml' : 'text/html';
  }

  // DOM only for HTML/XML content
  if (!preg_match('/(x|ht)ml/i', $type, $xmlMatches)) {
    return;
  }
  $charset = null;
  if (false !== ($pos = stripos($type, 'charset='))) {
    $charset = substr($type, $pos + 8);
    if (false !== ($pos = strpos($charset, ';'))) {
      $charset = substr($charset, 0, $pos);
    }
  }

  // http://www.w3.org/TR/encoding/#encodings
  // http://www.w3.org/TR/REC-xml/#NT-EncName
  if (null === $charset && preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9_:.]+)/i', $content, $matches)) {
    $charset = $matches[1];
  }
  if (null === $charset) {
    $charset = 'ISO-8859-1';
  }
  if ('x' === $xmlMatches[1]) {
    $this
      ->addXmlContent($content, $charset);
  }
  else {
    $this
      ->addHtmlContent($content, $charset);
  }
}