DiDom\Document::__construct PHP Method

__construct() public method

Constructor.
public __construct ( string $string = null, boolean $isFile = false, string $encoding = 'UTF-8', string $type = 'html' )
$string string HTML or XML string or file path
$isFile boolean Indicates that in first parameter was passed to the file path
$encoding string The document encoding
$type string The document type
    public function __construct($string = null, $isFile = false, $encoding = 'UTF-8', $type = 'html')
    {
        if ($string instanceof DOMDocument) {
            $this->document = $string;
            return;
        }
        if (!is_string($encoding)) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 3 to be string, %s given', __METHOD__, gettype($encoding)));
        }
        $this->document = new DOMDocument('1.0', $encoding);
        $this->preserveWhiteSpace(false);
        if ($string !== null) {
            $this->load($string, $isFile, $type);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Constructor.
  *
  * @param mixed  $html
  * @param string $currentUri The current URI
  * @param string $baseHref   The base href value
  */
 public function __construct($html = null, $currentUri = null, $baseHref = null)
 {
     $this->uri = $currentUri;
     $this->baseHref = $baseHref ?: $currentUri;
     if ($currentUri === null and filter_var($html, FILTER_VALIDATE_URL) !== false) {
         $this->uri = $html;
     }
     parent::__construct($html);
 }