blacknight Posted April 5, 2007 Share Posted April 5, 2007 im looking for a way to get info from a html page in php i have a code that was sapose to work but no longer does any one have any ideas on how to make it work? here is the code <?php $realmstatus = utf8_decode('Total Characters:'); $realmstatus = trim($realmstatus); $url = 'http://www.warcraftrealms.com/census.php?serverid=802&factionid=-1&minlevel=1&maxlevel=70&servertypeid=1'; $current_time = date('i')*1; if (function_exists('curl_init')) { $fp = curl_init( $url ); curl_setopt($fp, CURLOPT_HEADER, 0); curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1); $html = curl_exec($fp); if ( curl_errno($fp) ) { $ch_err = 1; } else { $ch_err = 0; } curl_close($fp); } else { $html = @file_get_contents($url); } //==========[ HTML PARSER ]============================================================ if (isset($html) && $html) { if (!preg_match('/\<tr(.(?!\<tr))*('.str_replace("'",''',$realmstatus).')(.(?!\<\/tr))*/si',$html,$matches)) { $err = 1; } elseif (preg_match_all('/^.*color: #([0-9a-fA-F]+);\">([^<]*)/m',$matches[0],$row) != 3) { $err = 1; } //print_r($row); //die(); } else { $err = 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45648-get-info-from-a-html-page-with-php/ Share on other sites More sharing options...
trq Posted April 5, 2007 Share Posted April 5, 2007 i have a code that was sapose to work but no longer does And the problem is? Quote Link to comment https://forums.phpfreaks.com/topic/45648-get-info-from-a-html-page-with-php/#findComment-221699 Share on other sites More sharing options...
blacknight Posted April 5, 2007 Author Share Posted April 5, 2007 it wont return the data like it should really i havent used this type of code much the page has numerical values on it and i want to get them on to my page to put them in a database. The phrase "Total Characters:" is in a table and looks like <tr> <td class="category">Total Characters:</td> <td><b>9,352</b></td> </tr> this i am trying to return the number 9,352 and its not worken.. Quote Link to comment https://forums.phpfreaks.com/topic/45648-get-info-from-a-html-page-with-php/#findComment-221703 Share on other sites More sharing options...
HaLo2FrEeEk Posted April 5, 2007 Share Posted April 5, 2007 Try using the snoopy library instead of cURL to get the page itself, here is the snoopy library: http://claninfectionist.com/misc/snoopy.phps Just save that code as a php file, then include it in your page. The code to get a remote page and store the source code of that page would be this: include('snoopy.php'); $snoopy = new Snoopy; if($snoopy->fetch("URL")) $text = ($snoopy->results); The variable $text would contain the source code of the page you requested. This is just a much simpler method of retrieving pages. That being said, to get the number that you need, try this(after calling up the page with snoopy): preg_match("|<td><b>(.+?)</b></td>|", $text, $match); This would be a VERY tentative way of doing it, since there could be multiple lines that follow that format, but if there are not, then this would work, it will return two values to the array $match, your array will be this: Array ( [0] => <td><b>9,352</b></td> [1] => 9,352 ) but when you do print_r($match), it will return this: Array ( [0] => 9,352 [1] => 9,352 ) Anywho, I hope this helps at least a little, and like I said, feel free to use the snoopy library, its way easier than cURL. Quote Link to comment https://forums.phpfreaks.com/topic/45648-get-info-from-a-html-page-with-php/#findComment-221751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.