-
-
Save surferxo3/8b4eafe499f7fa52eacb6cc187d0a49a to your computer and use it in GitHub Desktop.
<?php | |
/*############################# | |
* Developer: Mohammad Sharaf Ali | |
* Designation: Web Developer | |
* Version: 1.0 | |
*/############################# | |
const RATES_API_URL = 'http://goldprice.org/NewCharts/gold/images/goldsilverpricesforcalculators.txt'; | |
/* | |
* since the api returns text response so file_get_contents() will suffice | |
* else use curl get request | |
*/ | |
$fileContent = file_get_contents(RATES_API_URL); | |
$silverFileContent = explode('!', $fileContent); | |
$goldFileContent = explode('@', $silverFileContent[1]); | |
$currAndRateCollection = array(); | |
/* | |
* calculating gold and silver rates in different for each loops | |
* as the currencies return may vary across both | |
*/ | |
#gold rates calculation | |
$currAndRates = explode(';', $goldFileContent[0]); | |
foreach ($currAndRates as $currAndRate) { | |
if (!empty($currAndRate)) { | |
$split = explode(',', $currAndRate); | |
$currAndRateCollection['gold_rates'][] = array('Currency' => str_replace('XAU_', '', $split[0]), | |
'Price' => $split[1]); | |
} | |
} | |
#silver rates calculation | |
$currAndRates = explode(';', $silverFileContent[2]); | |
foreach ($currAndRates as $currAndRate) { | |
if (!empty($currAndRate)) { | |
$split = explode(',', $currAndRate); | |
$currAndRateCollection['silver_rates'][] = array('Currency' => str_replace('XAG_', '', $split[0]), | |
'Price' => $split[1]); | |
} | |
} | |
echo json_encode($currAndRateCollection); |
Any one share currency exchange Json format or API link...
Any one share currency exchange Json format or API link...
Can you show some code or any refrence!?
To fetch and store data from API: https://cmstoddler.com/curl-request-insert-record-mysql-database-php
To schedule a Cron Job: https://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800
Does it get the rates as 15 minutes late?
WILL THE ABOVE SHARED CODE FETCH GOLD PRICE FOR ALL CURRENCIES FOR DIFFERENT UNITS AND MEASUREMENT, LIKE 10GM GOLD PRICE IN INDIA, 20 gm gold price in Dubai, etc or it will fetch only in one currency, unit for a specific country. Please answer my query
do we have new link ?
The website is now using the following link(s) to fetch the rates:
To test out the API, substitute it with different values.
thanks.
do you have any others links to get prices?
thanks. do you have any others links to get prices?
Give this a try https://gist.github.com/StevenTso/b340fac0718252071e91017d7c53102e
Thanks a lot @StevenTso
if I can ask.. but if i would subscribe to "official" prices , like zurigo or london exchanges.. do you know a services ? obviously paying..
The website is now using the following link(s) to fetch the rates:
To test out the API, substitute it with different values.
How to get the values in g (grams), i need to get the gold price in India.
@anburocky3
you can calculate it if you have price of ounce
search in google about the math
its easy.
((price / ounce) * rank gold) / 24
Can you show some code or any refrence!?