Beispiel #1
0
 /**
  * @param string $html
  *
  * @return Document
  */
 private function document($html)
 {
     $doc = new Document();
     $doc->html($html);
     // Remove the doctype (if it exists) so we can use \DOMDocument::$firstChild
     if ($doc->doctype instanceof \DOMDocumentType) {
         $doc->removeChild($doc->doctype);
     }
     return $doc;
 }
Beispiel #2
0
 /**
  * @param string $html
  *
  * @return Document
  */
 private function document($html)
 {
     $doc = new Document();
     $doc->html($html);
     // Remove the doctype (if it exists) so we can use Document::$firstChild
     if ($doc->doctype instanceof \DOMDocumentType) {
         $doc->removeChild($doc->doctype);
     }
     // Remove any leading ProcessingInstructions
     if ($doc->firstChild instanceof \DOMProcessingInstruction) {
         $doc->removeChild($doc->firstChild);
     }
     return $doc;
 }
Beispiel #3
0
 /**
  * @param string $html
  *
  * @return Document
  */
 private function document($html)
 {
     $doc = new Document();
     $doc->html($html);
     // Remove any DOMProcessingInstruction/DOMDocumentType nodes from the base document
     //  so we can use \DOMDocument::$firstChild
     $length = $doc->childNodes->length;
     for ($i = 0; $i < $length; $i++) {
         $node = $doc->childNodes->item($i);
         if ($node instanceof \DOMProcessingInstruction || $node instanceof \DOMDocumentType) {
             $doc->removeChild($node);
         }
     }
     return $doc;
 }
Beispiel #4
0
 /**
  * @param string $rawHTML
  *
  * @return Document
  */
 private function getDocument($rawHTML)
 {
     $doc = new Document();
     $doc->html($rawHTML);
     return $doc;
 }
Beispiel #5
0
 /**
  * @param Document $doc
  * @param string $tag
  * @param string $property
  * @param string $value
  *
  * @return \DOMWrap\NodeList
  */
 private function getNodesByLowercasePropertyValue(Document $doc, $tag, $property, $value)
 {
     return $doc->findXPath("descendant::" . $tag . "[translate(@" . $property . ", 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='" . $value . "']");
 }