Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $enableLookupSpecificCurrency = false; $generateHeader = true; $currency = "JPY"; $exchangeAmount = 100000; $url = "https://xescanner.com/?country=Malaysia&state=Kuala+Lumpur&city=Kuala+Lumpur&currency=$currency&amount=$exchangeAmount&calculate=selected_to_local"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); if ($response === false) { $error = curl_error($curl); echo 'cURL error occurred: ' . $error; } curl_close($curl); $htmlSnippet = $response; // Generate the header if ($generateHeader == true) { echo "Name" . "\t"; echo "Currency" . "\t"; echo "Unit" . "\t"; echo "Buy Rate" . "\t"; echo "Sell Rate" . "\t"; echo "Buy Value" . "\t"; echo "Sell Value" . "\t"; echo "Updated Time" . "\n"; } $dom = new DOMDocument(); @$dom->loadHTML($htmlSnippet); $rows = $dom->getElementsByTagName('tr'); $data = array(); foreach ($rows as $row) { $cols = $row->getElementsByTagName('td'); if ($cols->length >= 8) { $nameElement = $cols->item(0)->getElementsByTagName('a')->item(1); $name = trim($nameElement->nodeValue); // Remove the Address element since we don't need it // $addressElement = $cols->item(0)->getElementsByTagName('a')->item(0); // $address = trim($addressElement->nodeValue); $unitElement = $cols->item(2); $unit = trim(str_replace($currency, '', $unitElement->nodeValue)); $buyRate = $cols->item(3)->nodeValue; $sellRate = $cols->item(4)->nodeValue; $updateTime = $cols->item(5)->nodeValue; $buyValue = trim($cols->item(6)->nodeValue); $sellValue = trim($cols->item(7)->nodeValue); $data[] = array( 'Name' => $name, // 'Address' => $address, 'Currency' => $currency, 'Unit' => $unit, 'Buy Rate' => $buyRate, 'Sell Rate' => $sellRate, 'Buy Value' => $buyValue, 'Sell Value' => $sellValue, 'Updated Time' => $updateTime, ); } } // Output the data as tab-delimited text foreach ($data as $row) { echo implode("\t", $row) . "\n"; } ?>
Copy Clear