Bman900 Posted August 5, 2012 Share Posted August 5, 2012 In my site I would need to display currency rates, I am thinking of getting such info from an official page but can I do this automatically somehow with PHP? Meaning the info is somewhere on the page and I want to somehow grab that little piece of information. I was thinking maybe I need a spider, and if so can any one point me to a good tutorial to get started? Quote Link to comment https://forums.phpfreaks.com/topic/266716-getting-specific-info-from-antother-site/ Share on other sites More sharing options...
.josh Posted August 5, 2012 Share Posted August 5, 2012 you can use file_get_contents or the cURL library to retrieve the contents of a page. Then you would use a DOM parser or regex functions (like preg_match_all) to scrape the values off the page. WARNING: You should always get permission from the site owner before scraping their content. People do not take kindly to others scraping their content and doing so has adverse effects. You may have your IP blocked or you could get sued, depending on lots of factors. I know there are a lot of sites that offer ability to grab current currency rates through a feed or an api. You will more than likely have to pay for such service, depending on how current you want the information to be, though. Quote Link to comment https://forums.phpfreaks.com/topic/266716-getting-specific-info-from-antother-site/#findComment-1367039 Share on other sites More sharing options...
Bman900 Posted August 5, 2012 Author Share Posted August 5, 2012 Wow, thank you for the information. You have given me a lot of think about and do. Again thank you! Quote Link to comment https://forums.phpfreaks.com/topic/266716-getting-specific-info-from-antother-site/#findComment-1367048 Share on other sites More sharing options...
Bman900 Posted August 6, 2012 Author Share Posted August 6, 2012 Alright I went with the XML route and found a bank that does this and I got it to read partially. <Rate currency="AED">1.0338</Rate> I can not get the rate out from between the brackets. Here is the code am using: <?php $XML=simplexml_load_file("http://www.bnr.ro/files/xml/curs_2012_8_3.xml"); foreach($XML->Body->Cube->Rate as $rate){ //Output the value of 1EUR for a currency code echo '1 LEI ='.$rate["rate"].' '.$rate["currency"].'<br/>'; //-------------------------------------------------- //Here you can add your code for inserting //$rate["rate"] and $rate["currency"] into your database //-------------------------------------------------- } ?> I will only print the AED part. Quote Link to comment https://forums.phpfreaks.com/topic/266716-getting-specific-info-from-antother-site/#findComment-1367059 Share on other sites More sharing options...
Davie33 Posted August 6, 2012 Share Posted August 6, 2012 oops wrong topic . Quote Link to comment https://forums.phpfreaks.com/topic/266716-getting-specific-info-from-antother-site/#findComment-1367060 Share on other sites More sharing options...
Bman900 Posted August 6, 2012 Author Share Posted August 6, 2012 Ah I solved it with using echo '1 LEI ='.$rate .' '.$rate["currency"].'<br/>'; Thank you for the help every one! Quote Link to comment https://forums.phpfreaks.com/topic/266716-getting-specific-info-from-antother-site/#findComment-1367062 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.