<?php
    // Finding 'php' in the string
 // 'i' means CASE SENSITIVE
 if (ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
     echo $reg[3] . $reg[2] . $regs[1];
 }
 else {
     echo "Ivalid date format:$date";
 }
?>