<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<?php
error_reporting(E_ALL & ~ E_NOTICE);
$html = file_get_contents("http://www.agropan.coop.br/cotac.htm");
$DOM = new DOMDocument();
libxml_use_internal_errors(true);
$DOM->loadHTML($html);
libxml_clear_errors();
$finder = new DomXPath($DOM);
$classname = 'MsoNormal';
$nodes = $finder->query("//*[contains(@class, '$classname')]");
foreach ($nodes as $node) {
$result=$result.$node->nodeValue."***";
}
$result = preg_replace(array("/\t/", "/\s{2,}/", "/\n/"), array("", " ", " "), $result);
$partes = explode('***',$result);
$cotacoes=$partes[0];
$cotacoes = trim(preg_replace('/[\r\n]+/', '', $cotacoes));
$cotacoes = str_replace("COTAÇÕES", "", $cotacoes);
echo $cotacoes;
?>
Other ways to avoid errors due to invalid entities "Tag o: p invalid in Entity".
1: Replacing these invalid entities:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<?php
error_reporting(E_ALL & ~ E_NOTICE);
$html = file_get_contents("http://www.agropan.coop.br/cotac.htm");
$search = array("<o:p>", "</o:p>");
$replace = array("", "","<div>");
$html = str_replace($search, $replace, $html);
$DOM = new DOMDocument();
$DOM->loadHTML($html);
$finder = new DomXPath($DOM);
$classname = 'MsoNormal';
$nodes = $finder->query("//*[contains(@class, '$classname')]");
foreach ($nodes as $node) {
$result=$result.$node->nodeValue."***";
}
$result = preg_replace(array("/\t/", "/\s{2,}/", "/\n/"), array("", " ", " "), $result);
$partes = explode('***',$result);
$cotacoes=$partes[0];
$cotacoes = trim(preg_replace('/[\r\n]+/', '', $cotacoes));
$cotacoes = str_replace("COTAÇÕES", "", $cotacoes);
echo $cotacoes;
?>
2: Using a @ in $ DOM-> loadHTML ($ html); '@ $ DOM-> loadHTML ($ html);
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<?php
error_reporting(E_ALL & ~ E_NOTICE);
$html = file_get_contents("http://www.agropan.coop.br/cotac.htm");
$DOM = new DOMDocument();
@$DOM->loadHTML($html);
$finder = new DomXPath($DOM);
$classname = 'MsoNormal';
$nodes = $finder->query("//*[contains(@class, '$classname')]");
foreach ($nodes as $node) {
$result=$result.$node->nodeValue."***";
}
$result = preg_replace(array("/\t/", "/\s{2,}/", "/\n/"), array("", " ", " "), $result);
$partes = explode('***',$result);
$cotacoes=$partes[0];
$cotacoes = trim(preg_replace('/[\r\n]+/', '', $cotacoes));
$cotacoes = str_replace("COTAÇÕES", "", $cotacoes);
echo $cotacoes;
?>
By id just replace
$classname = 'MsoNormal';
$nodes = $finder->query("//*[contains(@class, '$classname')]");
by
$id = 'MsoNormal';
$nodes = $finder->query("//*[contains(@id, '$id')]");