stormx Posted August 30, 2008 Share Posted August 30, 2008 Hello all, I currently need a script that can export an .xml conents to a database. I need it to export a script hosted on a remote server. To access it, you need usagemeter.php?username,password & when the login data is right, it will echo something like the following if correct: username=username<br>data_down=15395.81 MB<br>data_up=2566.44 MB<br>free_data_down=27543.70 MB<br>free_data_up=6541.70 MB Now I need to export the data_down & free_data_down to a MySQL database, just the figures. Is their a script that can do that? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/ Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 You could always just explode() at the line breaks then seek out the correct lines and explode at the =, getting the part after it to put into the DB. Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629506 Share on other sites More sharing options...
JasonLewis Posted August 30, 2008 Share Posted August 30, 2008 Going on what DarkWater said, try something like this: <?php $str = "username=username<br>data_down=15395.81 MB<br>data_up=2566.44 MB<br>free_data_down=27543.70 MB<br>free_data_up=6541.70 MB"; $tmp_explode = explode("<br>", $str); $data = array(); foreach($tmp_explode as $line){ $tmp_line = explode("=", $line); $data[$tmp_line[0]] = $tmp_line[1]; } echo "<pre>"; print_r($data); echo "</pre>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629507 Share on other sites More sharing options...
stormx Posted August 30, 2008 Author Share Posted August 30, 2008 The usage meter is here: https://www.exetel.com.au/members/usagemeter.php How could I obtain the data from that page where the $str = funtion is? Also can just the 15395.81 MB be echoed on the page with removing everything else on it? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629516 Share on other sites More sharing options...
JasonLewis Posted August 30, 2008 Share Posted August 30, 2008 The usage meter is here: https://www.exetel.com.au/members/usagemeter.php How could I obtain the data from that page where the $str = funtion is? Sorry I'm not sure what you mean. Could you explain a bit more. Also can just the 15395.81 MB be echoed on the page with removing everything else on it? You can echo just the 15395.81 MB by doing this: echo $data['data_down']; Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629522 Share on other sites More sharing options...
stormx Posted August 30, 2008 Author Share Posted August 30, 2008 Thanks for the code just to obtain the data down. What I meant about obtaining that page is using fsock or something to connect to that remote script and getting the live data, can that be done? Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629524 Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 file_get_contents() or cURL. Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629526 Share on other sites More sharing options...
stormx Posted August 30, 2008 Author Share Posted August 30, 2008 <?php $link = "https://www.exetel.com.au/members/usagemeter.php?username,password"; $http_response = ""; $url = parse_url($link); $fp = fsockopen($url[host], 80, $err_num, $err_msg, 30) or die("Socket-open failed--error: ".$err_num." ".$err_msg); fputs($fp, "GET /$url[path]?$url[query] HTTP/1.0\n"); fputs($fp, "Connection: close\n\n"); while(!feof($fp)) { $http_response .= fgets($fp, 128); } fclose($fp); $str = $http_response; $tmp_explode = explode("<br>", $str); $data = array(); foreach($tmp_explode as $line){ $tmp_line = explode("=", $line); $data[$tmp_line[0]] = $tmp_line[1]; } echo "<pre>"; echo $data['data_down']; echo "</pre>"; ?> Would it be something like this or am I wrong? Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629529 Share on other sites More sharing options...
stormx Posted August 30, 2008 Author Share Posted August 30, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/121953-solved-exporting-xml-to-a-database/#findComment-629613 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.