Yahoo Finance – Parse Stock Currency

How to parse the stock currency in Yahoo Finance?

You can use the following script

This script will parse the currency out of a Yahoo Finance page.

mattionline:/home/stock# cat fetchcurrency.php

if($argv[1] != "") {

$symbol = $argv[1];

$url = "".$symbol;

$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);

$dom = new DOMDocument();
$link = $dom->getElementById('quote-header-info');
preg_match('/Währung in (.*?)[+-]/', $link->textContent, $found);
$test = explode("Z", $found[1]);
$currency = $test[0];

echo $currency;



Output of the script

If you pass the parameter (SOBA.DE) (which is the shortcode from Yahoo Finance for the AT&T company), you will get the EUR symbol as a result, because the symbol is from the German stock exchange XETRA (€).

If you pass the Calida Stock, you will receive the currency swiss francs (CHF).

mattionline:/home/stock# php -f fetchcurrency.php SOBA.DE
mattionline:/home/stock# php -f fetchcurrency.php CALN.SW

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Scroll to Top