DomDocumentParser.php 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class DomDocumentParser
  3. {
  4. private $doc;
  5. public function __construct($url)
  6. {
  7. $html = '<?xml encoding="UTF-8">';
  8. $options = array(
  9. 'http'=>array('method'=>"GET", 'header'=>"User-Agent: doogleBot/0.1\n")
  10. );
  11. $context = stream_context_create($options);
  12. $getConstants = file_get_contents($url, false, $context);
  13. $this->doc = new DomDocument('1.0', 'utf-8');
  14. @$this->doc->loadHTML($html . $getConstants);
  15. //@ Error supression is unnecessary, PHP>7.0 supports HTML5
  16. }
  17. public function getlinks()
  18. {
  19. return $this->doc->getElementsByTagName("a");
  20. }
  21. public function getTitleTags()
  22. {
  23. return $this->doc->getElementsByTagName("title");
  24. }
  25. public function getMetaTags()
  26. {
  27. return $this->doc->getElementsByTagName("meta");
  28. }
  29. public function getImages()
  30. {
  31. return $this->doc->getElementsByTagName("img");
  32. }
  33. }
  34. ?>