text = file_get_contents( '/tmp/knowmore' ); $this->getAllTitles(); return; } $this->text = file_get_contents( 'http://www.knowmore.org/index.php?title=Special:Browse&filter=all&id=1' ); $fh = fopen( '/tmp/knowmore', 'w' ); fwrite( $fh, $this->text ); fclose($fh); $this->getAllTitles(); } /** * Scrapes the data into an array. */ function &getAllTitles() { if (file_exists('/tmp/knowmore.db')) { $this->data = unserialize( file_get_contents('/tmp/knowmore.db') ); return $this->data; } // else parse the data and save it $this->text = file_get_contents( '/tmp/knowmore' ); $this->data = array(); $count = preg_match_all( '/a href="([^>]+?)" title ="(.+?)"/im', $this->text, $matches, PREG_SET_ORDER ); // print_r($matches); reset($matches); foreach($matches as $match) { $this->data[] = array( $match[1], $match[2] ); } $fh = fopen( '/tmp/knowmore.db', 'w' ); fwrite( $fh, serialize($this->data) ); fclose($fh); return $this->data; } function asJsArray() { reset($this->data); foreach( $this->data as $link ) { if ($result) $result .= ', '; $result .= '[ \''. addslashes( $link[1] ) .'\', '; $result .= '\''. 'http://knowmore.org' . $link[0] .'\' ]'; } return '['.$result . '];'; } } $w = new KnowMore( ); ?>