function timetable($route, $stopcode) { $this->get_data(sprintf('http://www.tfl.gov.uk/tfl/syndication/feeds/html/timetables/buses/%s_%s.htm', $route, $stopcode), NULL, 'html-dom'); $css2xpath = new CSS2XPath(); $xpath = $css2xpath->transform('.TT_DayType'); $nodes = $this->xpath->query($xpath); foreach ($nodes as $node) { if ($node['class'] == 'TT_DayType c5') { $day = (string) $node->tr->td->p; continue; } if (!$day) { continue; } $headers = $node->tr[0]->th; $items = $node->tr[1]->td; for ($i = 0; $i < count($headers); $i++) { $header = preg_replace('/\\s+/', ' ', (string) $headers[$i]); $item = isset($items[$i]->table) ? innerXML($items[$i]->table->tr->td) : outerXML($items[$i]); $this->results[$day][$header] = $item; } } }
/** * Copyright 2010 jubianchi.fr * * @author jubianchi */ ini_set('display_errors', 1); $url = null; $selector = null; if (isset($_GET['txtUrl'])) { $url = $_GET['txtUrl']; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { require_once '../CSS2XPath.php'; $selector = $_POST['txtSelector']; $xpath = CSS2XPath::parse($selector); function dumpNodeList(DOMNodeList $list) { //echo '<b>Found ' . $list -> length . ' element(s)</b>'; echo '<pre style="height: 190px; overflow: auto">'; foreach ($list as $node) { echo $node->localName . '('; $sep = ''; foreach ($node->attributes as $attr) { echo $sep . $attr->name . '="' . $attr->value . '"'; $sep = ', '; } echo ')' . "\n"; } echo '</pre>'; }