September 2009


Just sharing this currency converter script that I used on my website.
Feel free to modify it based on your needs.
It uses finance.yahoo.com conversion table.

<?php

$from = 'USD'; //US Dollar
$to = 'SAR'; //to Philippine Peso

$url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X';

$handle = @fopen($url, 'r');
if ($handle) {
    $result = fgets($handle, 4096);
    fclose($handle);
}

$array = explode(',',$result);

$a_convert=$array[1];
$a_date=$array[2];
$a_time=$array[3];
$a_date=preg_replace('/"/', ' ', $a_date);
$a_time=preg_replace('/"/', ' ', $a_time);

echo "1 USD <img src=us_ico_flag.jpg>  = $a_convert PHP <img src=ph_ico_flag.jpg> ";
echo "<br> $a_date / $a_time ";
echo "<br><a href=http://finance.yahoo.com/q?s=USDPHP=X>Powered by: Yahoo! Finance</a>";

?>

Just found this very simple & efficient way of validating email address with PHP.
You can use this to replace the usual regular expression email checking.

<?php
$email = "john@doe.com";

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      echo "Please check your email address";
} else {
      echo "Great! valid email address";
}
?>

Source:

http://www.php.net/filter_var