Jump to content

Find Character, Select Currency Code


ChadGregory

Recommended Posts

Alright So I cam trying to create a currency detection script and I got it all ironed out except for one part.

 

Basically how it is going works is, it grabs the page content of http://www.xe.com/symbols.php and searches for the currency symbol in the example of this post the symbol ( ¥ ).

 

Now I think I can find that symbol by doing a preg_match of that content which in the variable $data, but im not sure how to get it to grab the currency code from that same row in the table. I was thinking I might have to grab the whole tr and then search that, but Im not sure how i would do that either.

 

Here is a 3 row example of the structure of that page

<tr class="row2">
     <td>Chile Peso</td>
     <td>CLP</td><td class="cSmbl_imgCol">
          <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol36.gif">
     </td>
     <td class="cSmbl_Fnt_C2000">$</td>
     <td class="cSmbl_Fnt_AU">$</td>
     <td width="90px">36</td>
     <td>24</td>
     <td>	<a href="javascript:void(0);" class="curInfo">info</a></td>
</tr>
<tr class="row1">
     <td>China Yuan Renminbi</td>
     <td>CNY</td>
     <td class="cSmbl_imgCol">
          <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol165.gif">
     </td>
     <td class="cSmbl_Fnt_C2000">¥</td>
     <td class="cSmbl_Fnt_AU">¥</td>
     <td width="90px">165</td>
     <td>a5</td>
     <td>	<a href="javascript:void(0);" class="curInfo">info</a></td>
</tr>
<tr class="row2">
     <td>Colombia Peso</td>
     <td>COP</td>
     <td class="cSmbl_imgCol">
          <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol36.gif">
     </td>
     <td class="cSmbl_Fnt_C2000">$</td>
     <td class="cSmbl_Fnt_AU">$</td>
     <td width="90px">36</td>
     <td>24</td>
     <td> </td>
</tr>

So lets say $data is equal to that code above, How Would get the currency code when search for ( ¥ ) or how could I isolate that entire <tr> from the code.(I Could get the rest of it from there)

 

Here is my code

<?php

if (!function_exists('bb_file_contents')) {
	function bb_file_contents($url) {
		if(function_exists('curl_init')) {
			$ch = curl_init();
			$timeout = 0; // set to zero for no timeout
			
			curl_setopt ($ch, CURLOPT_URL, $url);
			curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
			curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	
			$file_contents = curl_exec($ch);
	
			if (!$file_contents) {
				print_r(curl_getinfo($ch));
				die;
			}
	
			curl_close($ch);
		}
		
		else {
			$file_contents = file_get_contents($url);
		}
		
		return $file_contents;
	}
}

$price = '¥6.09';
$convertURL = 'http://www.xe.com/currencyconverter/convert/?Amount=6.09&From=CNY&To=USD';
$currencyURL = 'http://www.xe.com/symbols.php';

echo substr($price, 2, 1);

$data = bb_file_contents($currencyURL);

//Find Currency Code


//Convert to other Currency

?>
Link to comment
https://forums.phpfreaks.com/topic/277849-find-character-select-currency-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.