Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/02/2010, 18:41
easy
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 11 meses
Puntos: 2
Respuesta: Convertir Monedas

currencies.class.php
Código PHP:
class currencyCoverter
{
    public 
$fromCurr 'USD';
    public 
$toCurr 'INR';
    function 
__construct($amount$to$from)
    {
        if(
intval($amount) > 0){
            
$this->amount intval($amount);
        }
        if(
trim($to) != ''){
            
$this->toCurr $to;
        }
        if(
trim($from) != ''){
            
$this->fromCurr $from;
        }
    }
    function 
getUpadte()
    {
        
$returnHtml = array();
        
$page 'http://www.google.com/search?&q='.$this->amount.'+' $this->fromCurr '+in+' $this->toCurr;
        
$returnRawHtml file_get_contents$page );    
        
preg_match_all('/<h2 class=r(.*)\<\/h2\>/Uis',$returnRawHtml,$returnHtml,PREG_PATTERN_ORDER);
        if (isset(
$returnHtml[0][0])) 
        {
          
$gRate strip_tags($returnHtml[0][0]);
          return 
$gRate;
        }
        else {
            return 
false;
        }

    }


y converter.php
Código PHP:
  require_once('currencies.class.php');
  $result = '';
  if(isset($_POST['FromCurrency']))
  {
      $FromCurrency = $_POST['FromCurrency'];
      $ToCurrency = $_POST['ToCurrency'];
      $convert = $_POST['Convert'];
      $amount =  $_POST['amount'];
      $converter = new currencyCoverter($amount, $ToCurrency, $FromCurrency); // get result
      if(!$converter->getUpadte())
      {
        $result = 'Sorry No Result Found! Please try again after some time.';
      }
      else
      {
        $result =  $converter->getUpadte();
      }
  }
?>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Currency Converter</title>
<meta name="author" content="Raj Trivedi">
<meta name="keywords" content="Raj Trivedi, Kanpur, PHP,Currency Converter">
<meta name="description" content="Raj Trivedi, Kanpur, PHP,Currency Converter">
</head>
<body>
<form name="currencyFrm" method="POST" action="">
<table border="0" cellpadding="2" cellspacing="2" width="550" align="center">
<tr>
    <td valign="top" align="center" colspan="2">
        <font size="3" face="Verdana" color="#2660DD"><b>Currency Converter</b></font><br><br> 
    </td> 
</tr>
<?php if($result != "")
{
    echo 
'<tr>
        <td valign="top" align="center" colspan="2">
            <font size="3" face="Verdana" color="#2660DD"><b>'
.$result.'</b></font><br/><br/> 
        </td> 
    </tr>
    <tr>
        <td valign="top" align="center" colspan="2">
            <font size="3" face="Verdana" color="#2660DD"><a href="converter.php">Try Again</a></font><br/><br/> 
        </td> 
    </tr>'
;
    exit;
}
?>
<tr>
    <td valign="top" align="left" width="200">
        <font size="2" face="Verdana" color="#3366CC"><b>Please enter the amount:</b></font>
    </td>
    <td>
        <INPUT NAME="amount" VALUE="1" SIZE="4" maxlength="3" style="font-family: Arial; font-size: 8pt"> [Numeric Value]
    </td> 
</tr>
<tr>
    <td valign="top" align="left" width="275">
        <font size="2" face="Verdana" color="#3366CC"><b>From Currency:</b></font>
    </td> 
    <td>
        <select size="1" name="FromCurrency" style="font-size: 8pt; font-family: Arial">
            <option value="AUD">AUD Australia Dollars</option>
            <option value="CAD">CAD Canada Dollars</option>
            <option value="CHF">CHF Switzerland Francs</option>
            <option value="CNY">CNY China Yuan Renminbi</option>
            <option value="DKK">DKK Denmark Kroner</option>
            <option value="EUR">EUR Euro</option>
            <option value="GBP">GBP United Kingdom Pounds</option>
            <option value="HKD">HKD Hong Kong Dollars</option>
            <option value="HUF">HUF Hungary Forint</option>
            <option value="INR">INR India Rupees</option>
            <option value="JPY">JPY Japan Yen</option>
            <option value="MXN">MXN Mexico Pesos</option>
            <option value="MYR">MYR Malaysia Ringgits</option>
            <option value="NOK">NOK Norway Kroner</option>
            <option value="NZD">NZD New Zealand Dollars</option>
            <option value="RUB">RUB Russia Rubles</option>
            <option value="SEK">SEK Sweden Kronor</option>
            <option value="SGD">SGD Singapore Dollars</option>
            <option value="THB">THB Thailand Baht</option>
            <option value="USD" selected="selected">USD United States Dollars</option>
            <option value="ZAR">ZAR South Africa Rand</option>
        </select>
    </td>
</tr>
<tr>
    <td valign="top" align="left" width="275">
        <font size="2" face="Verdana" color="#3366CC"><b>To Currency:</b></font>
    </td> 
    <td>
        <select size="1" name="ToCurrency" style="font-size: 8pt; font-family: Arial">
            <option value="AUD">AUD Australia Dollars</option>
            <option value="CAD">CAD Canada Dollars</option>
            <option value="CHF">CHF Switzerland Francs</option>
            <option value="CNY">CNY China Yuan Renminbi</option>
            <option value="DKK">DKK Denmark Kroner</option>
            <option value="EUR">EUR Euro</option>
            <option value="GBP">GBP United Kingdom Pounds</option>
            <option value="HKD">HKD Hong Kong Dollars</option>
            <option value="HUF">HUF Hungary Forint</option>
            <option value="INR" selected="selected">INR India Rupees</option>
            <option value="JPY">JPY Japan Yen</option>
            <option value="MXN">MXN Mexico Pesos</option>
            <option value="MYR">MYR Malaysia Ringgits</option>
            <option value="NOK">NOK Norway Kroner</option>
            <option value="NZD">NZD New Zealand Dollars</option>
            <option value="RUB">RUB Russia Rubles</option>
            <option value="SEK">SEK Sweden Kronor</option>
            <option value="SGD">SGD Singapore Dollars</option>
            <option value="THB">THB Thailand Baht</option>
            <option value="USD">USD United States Dollars</option>
            <option value="ZAR">ZAR South Africa Rand</option>
        </select>
    </td>
</tr>
<tr>
    <td valign="top" align="center" colspan="2"> 
        <INPUT type="submit" name="Convert" VALUE="Convert" SIZE=7 style="font-family: Arial; font-size: 8pt">
    </td> 
</tr>
</table>
</form>
</body>
</html>

muy util, saludos