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',
27 * Parses the body of /index_wstatus1.asp and returns extracted values.
29 * @param string $body HTML document to parse
31 * @return array Array of key-value pairs
33 public function index_wstatus1($body)
37 preg_match_all('#>Capture\(([^)]+)\)</#', $body, $arMatches);
40 while (current($arMatches[1])) {
41 $key = current($arMatches[1]);
42 $value = next($arMatches[1]);
43 if (isset(self::$arTranslations[$key])) {
44 $key = self::$arTranslations[$key];
46 if (isset(self::$arTranslations[$value])) {
47 $value = self::$arTranslations[$value];
49 $arRetval[$key] = $value;
59 * Parses the body of /index_wstatus2.asp and returns extracted values.
61 * @param string $body HTML document to parse
63 * @return array Array with "connection" as key and one of "connecting",
64 * "connected" or "disconnected" as value.
66 public function index_wstatus2($body)
68 preg_match('/var status2 = "(.+)"/', $body, $arMatches);
70 $strStatus = $arMatches[1];
74 return array('connection' => strtolower($strStatus));