diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2010-12-13 19:21:20 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2010-12-13 19:21:20 +0100 |
| commit | c5139cfd6db3f77bfd3bb3dc36bb915c8a014e0f (patch) | |
| tree | b5f0edbd0fc335377ee4f137346c365216bbd5d2 | |
| parent | 126f3b06d394c5252eaf308b55d8f6933ea48265 (diff) | |
| download | linksys-wrt3g-tools-c5139cfd6db3f77bfd3bb3dc36bb915c8a014e0f.tar.gz linksys-wrt3g-tools-c5139cfd6db3f77bfd3bb3dc36bb915c8a014e0f.zip | |
make the tests work by implementing proper html parsing :/
| -rw-r--r-- | Wrt3g/HtmlParser.php | 41 | ||||
| -rw-r--r-- | tests/index_wstatus1-connected-excellent.phpt | 6 | ||||
| -rw-r--r-- | tests/index_wstatus1-connected-good.phpt | 6 |
3 files changed, 40 insertions, 13 deletions
diff --git a/Wrt3g/HtmlParser.php b/Wrt3g/HtmlParser.php index 03ac574..970b170 100644 --- a/Wrt3g/HtmlParser.php +++ b/Wrt3g/HtmlParser.php @@ -19,6 +19,8 @@ class Wrt3g_HtmlParser 'GPRS_MSG.ACQUIRING' => 'aquiring', 'GPRS_MSG.WWBEAR_GPRS' => 'GPRS', 'GPRS_MSG.WWBEAR_UMTS' => 'UMTS', + 'GPRS_MSG.GOOD' => 'good', + 'GPRS_MSG.EXCELLENT' => 'excellent', ); @@ -32,14 +34,39 @@ class Wrt3g_HtmlParser */ public function index_wstatus1($body) { - $arRetval = array(); + $doc = new DomDocument(); + $doc->loadHtml($body); + $xpath = new DOMXPath($doc); + $entries = $xpath->query('//table/tr/td'); + $arMatches = array(); - preg_match_all('#>Capture\(([^)]+)\)</#', $body, $arMatches); + foreach ($entries as $entry) { + $s = $doc->saveXML($entry); + $s = str_replace( + array('<![CDATA[', ']]>'), + '', $s + ); + $s = strip_tags($s); + //some strange utf8 space char + $s = str_replace("\xC2\xA0", ' ', $s); + $s = trim($s); + $s = str_replace( + array('Capture(', ') :'), + '', $s + ); + if (substr($s, -1) == ')') { + $s = substr($s, 0, -1); + } + $arMatches[] = $s; + } + + + $arRetval = array(); $arData = array(); - reset($arMatches[1]); - while (current($arMatches[1])) { - $key = current($arMatches[1]); - $value = next($arMatches[1]); + reset($arMatches); + while (current($arMatches)) { + $key = current($arMatches); + $value = next($arMatches); if (isset(self::$arTranslations[$key])) { $key = self::$arTranslations[$key]; } @@ -47,7 +74,7 @@ class Wrt3g_HtmlParser $value = self::$arTranslations[$value]; } $arRetval[$key] = $value; - next($arMatches[1]); + next($arMatches); } return $arRetval; diff --git a/tests/index_wstatus1-connected-excellent.phpt b/tests/index_wstatus1-connected-excellent.phpt index 363a940..4bfb354 100644 --- a/tests/index_wstatus1-connected-excellent.phpt +++ b/tests/index_wstatus1-connected-excellent.phpt @@ -13,9 +13,9 @@ var_dump( --EXPECT-- array(3) { ["type"]=> - string(8) "GPRS" + string(4) "GPRS" ["network"]=> - string(8) "BASE DE" + string(7) "BASE DE" ["signal strength"]=> - string(8) "excellent" + string(9) "excellent" } diff --git a/tests/index_wstatus1-connected-good.phpt b/tests/index_wstatus1-connected-good.phpt index a78bcc9..926df8e 100644 --- a/tests/index_wstatus1-connected-good.phpt +++ b/tests/index_wstatus1-connected-good.phpt @@ -13,9 +13,9 @@ var_dump( --EXPECT-- array(3) { ["type"]=> - string(8) "GPRS" + string(4) "GPRS" ["network"]=> - string(8) "BASE DE" + string(7) "BASE DE" ["signal strength"]=> - string(8) "good" + string(4) "good" } |
