fork(1) download
  1. <?php
  2.  
  3. class DevelopersUtils {
  4.  
  5. public function extract($url, $value) {
  6.  
  7. $dom = new DOMDocument();
  8.  
  9. $file = 'content.txt';
  10. //$current = file_get_contents($url);
  11. $current = CurlTool::downloadFile($url, $file);
  12. //file_put_contents($file, $current);
  13.  
  14. @$dom->loadHTMLFile($current);
  15.  
  16. //use DOMXpath to navigate the html with the DOM
  17. $dom_xpath = new DOMXpath($dom);
  18.  
  19. $results = $dom_xpath->query('//td1'); // (or any offending element)
  20. foreach ($results as $invalidNode) {
  21. $parentNode = $invalidNode->parentNode;
  22. $children = $invalidNode->childNodes;
  23. foreach ($children as $childNode) {
  24. $parentNode->insertBefore($childNode, $invalidNode);
  25. }
  26. $parentNode->removeChild($invalidNode);
  27. }
  28.  
  29.  
  30. //die();
  31.  
  32. //$dom_xpath = new DOMXpath($dom);
  33.  
  34. $elements = $dom_xpath->query("//*[text()[contains(., '" . $value . "')]]");
  35. var_dump($elements);
  36. if (!is_null($elements)) {
  37.  
  38. foreach ($elements as $element) {
  39. var_dump($element);
  40. echo "\n1.[" . $element->nodeName . "]\n";
  41.  
  42. $nodes = $element->childNodes;
  43. foreach ($nodes as $node) {
  44. if (($node->nodeValue != null) && ($node->nodeValue === $value)) {
  45. echo '2.' . $node->nodeValue . "\n";
  46. $xpath = preg_replace("/\/text\(\)/", "", $node->getNodePath());
  47. echo '3.' . $xpath . "\n";
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54.  
  55. $o = new DevelopersUtils();
  56.  
  57. $o->extract('http://w...content-available-to-author-only...e.ro/preturi_canyon_4-in-1_stylus_bundle_pack_cng-ds03_199062.htm','Canyon 4-in-1 Stylus bundle pack CNG-DS03');
Runtime error #stdin #stdout 0.03s 13064KB
stdin
Standard input is empty
stdout
Fatal error: Class 'DOMDocument' not found in /home/7o7bwE/prog.php on line 7