3 * HTML parsing for the linksys router HTML pages
8 * @package linksys-wrt3g-tools
9 * @author Christian Weiske <cweiske@cweiske.de>
11 * @link http://cweiske.de/linksys-wrt3g-tools.htm
13 class Wrt3g_HtmlParser
15 protected static $arTranslations = array(
16 'GPRS_MSG.WWBEAR' => 'type',
17 'GPRS_MSG.NNAME' => 'network',
18 'GPRS_MSG.STRENGTH' => 'signal strength',
19 'GPRS_MSG.ACQUIRING' => 'aquiring',
20 'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
21 'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
22 'GPRS_MSG.GOOD' => 'good',
23 'GPRS_MSG.EXCELLENT' => 'excellent',
29 * Parses the body of /index_wstatus1.asp and returns extracted values.
31 * @param string $body HTML document to parse
33 * @return array Array of key-value pairs
35 public function index_wstatus1($body)
37 $doc = new DomDocument();
38 $doc->loadHtml($body);
39 $xpath = new DOMXPath($doc);
40 $entries = $xpath->query('//table/tr/td');
43 foreach ($entries as $entry) {
44 $s = $doc->saveXML($entry);
46 array('<![CDATA[', ']]>'),
50 //some strange utf8 space char
51 $s = str_replace("\xC2\xA0", ' ', $s);
54 array('Capture(', ') :'),
57 if (substr($s, -1) == ')') {
58 $s = substr($s, 0, -1);
67 while (current($arMatches)) {
68 $key = current($arMatches);
69 $value = next($arMatches);
70 if (isset(self::$arTranslations[$key])) {
71 $key = self::$arTranslations[$key];
73 if (isset(self::$arTranslations[$value])) {
74 $value = self::$arTranslations[$value];
76 $arRetval[$key] = $value;
86 * Parses the body of /index_wstatus2.asp and returns extracted values.
88 * @param string $body HTML document to parse
90 * @return array Array with "connection" as key and one of "connecting",
91 * "connected" or "disconnected" as value.
93 public function index_wstatus2($body)
95 preg_match('/var status2 = "(.+)"/', $body, $arMatches);
97 $strStatus = $arMatches[1];
101 return array('connection' => strtolower($strStatus));