puk Posted February 2, 2011 Share Posted February 2, 2011 Im using this code to get only the data and it returns nothing could someone help? $url = "http://www.athex.gr/content/en/announcements/companiespress/press_date.asp?dt=28/01/2011"; $input = @file_get_contents($url) or die("Could not access file: $url"); $regexp = '<td class="TDtitle">\s+<a name="(\d)+"><\/a>\s+<b>\s+<a href="(.)+">(.)+<\/a> : (.)+'; if(preg_match_all('/$regexp/si', $input, $matches, PREG_SET_ORDER)) { foreach($matches as $match) { echo '". $match[0] . "' / '" . $match[1] . "' / '" . $match[2] . "' / '" . $match[3] . "<br>"'; } } else { echo "no matches"; } Link to comment Share on other sites More sharing options...
0 sweetsam Posted February 2, 2011 Share Posted February 2, 2011 Try this. Its a lot less complicated. $data = file_get_contents('http://www.athex.gr/content/en/announcements/companiespress/press_date.asp?dt=28/01/2011'); $html = new DOMDocument(); @$html->loadHTML($data); foreach($html->getElementsByTagName('td') as $td): if ($td->getAttribute('class') === 'TDtitle'): foreach ($td->childNodes as $ch): $val = trim($ch->nodeValue); if (!empty($val)): echo $val . '<br>'; endif; endforeach; endif; endforeach; Link to comment Share on other sites More sharing options...
0 puk Posted February 4, 2011 Author Share Posted February 4, 2011 on the server runs php v4.4 and I can't use this class... Link to comment Share on other sites More sharing options...
0 sweetsam Posted February 4, 2011 Share Posted February 4, 2011 Php manual claims otherwise. The syntax is different but you can still do it. http://www.php.net/manual/en/function.domdocument-get-elements-by-tagname.php Link to comment Share on other sites More sharing options...
Question
puk
Im using this code to get only the data and it returns nothing could someone help?
$url = "http://www.athex.gr/content/en/announcements/companiespress/press_date.asp?dt=28/01/2011";
$input = @file_get_contents($url) or die("Could not access file: $url");
$regexp = '<td class="TDtitle">\s+<a name="(\d)+"><\/a>\s+<b>\s+<a href="(.)+">(.)+<\/a> : (.)+';
if(preg_match_all('/$regexp/si', $input, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
echo '". $match[0] . "' / '" . $match[1] . "' / '" . $match[2] . "' / '" . $match[3] . "<br>"';
}
} else {
echo "no matches";
}
Link to comment
Share on other sites
3 answers to this question
Recommended Posts