コード例 #1
0
ファイル: Postcode.php プロジェクト: citco/postcode
 private function checkPostcode(&$postcode)
 {
     if (strcasecmp($postcode, 'ai-2640') == 0) {
         return false;
     }
     return checkPostcode($postcode);
 }
コード例 #2
0
function getState($postcode)
{
    $url = 'http://www.auspost.com.au/postcode/' . $postcode;
    //$data = file_get_contents($url) or exit("Unable to open url: <br/>".$url);
    $data = getData($url) or exit("Unable to open url: <br/>" . $url);
    //echo $data;
    $regex = "/<td class=\"first\"><a class=\"result(?:.*)\" href=\"\\/(?:.*)\\/(?:.*)\\/(.*?)\\/(?:.*)\">" . $postcode . "<\\/a>/";
    preg_match($regex, $data, $state);
    $states = array('act', 'nsw', 'nt', 'qld', 'sa', 'tas', 'vic', 'wa');
    if (in_array($state[1], $states, true)) {
        return $state[1];
    } else {
        exit("Error finding state.");
    }
}
if (checkPostcode($postcode)) {
    $state = getState($postcode);
} else {
    exit("There is an issue. Please check regex.");
}
function getWeather($state, $postcode, $mycity, $mystate)
{
    //Generate url using state and postcode
    $url = 'https://weather.yahoo.com.au/local-forecast/' . $state . '/' . $postcode;
    //$data = file_get_contents($url) or exit("Unable to open weather url: <br/>".$url);
    $data = getData($url) or exit("Unable to open weather url: <br/>" . $url);
    // Get weather location name
    $regex = "/<span id='qualified_location_name' style='display: none;'>(.*?)<\\/span>/";
    preg_match($regex, $data, $loc);
    $autoloc = $loc[1];
    if (empty($autoloc)) {
コード例 #3
0
             }
             break;
         case "TAS":
             if (!preg_match("/^[7].*\$/", $bpostcode)) {
                 $errMsg = "<p>If you're from TAS your billing postcode starts with 7</p>";
             }
             break;
         case "ACT":
             if (!preg_match("/^[0].*\$/", $bpostcode)) {
                 $errMsg = "<p>If you're from ACT your billing postcode starts with 0</p>";
             }
             break;
     }
     return $errMsg;
 }
 $errMsg .= checkPostcode($bstate, $bpostcode);
 // Checks if the expiration date of the card is earlier than today's date
 function checkExpiry($date)
 {
     $cmm = substr($date, 0, 2);
     $cyy = substr($date, 3, 5);
     $expires = \DateTime::createFromFormat('my', $cmm . $cyy);
     $now = new \DateTime();
     if ($expires < $now) {
         return "<p>This creditcard has expired</p>";
     } else {
         return "";
     }
 }
 $errMsg .= checkExpiry($cardexpiry);
 // checks card number against the card type
コード例 #4
0
         case "TAS":
             if (!preg_match("/^[7].*\$/", $postcode)) {
                 $errMsg = "If you're from TAS your postcode starts with 7";
             }
             break;
         case "ACT":
             if (!preg_match("/^[0].*\$/", $postcode)) {
                 $errMsg = "If you're from ACT your postcode starts with 0";
             }
             break;
         default:
             $errMsg = "Please choose a state";
     }
     return $errMsg;
 }
 $errMsg .= checkPostcode($state, $postcode);
 if ($phone == "") {
     $errMsg .= "<p>You must enter your phone number.</p>";
 }
 if (!preg_match("/[0-9]{1,10}/", $phone)) {
     $errMsg .= "<p>Maximum of 10 characters for your phone number.</p>";
 }
 if (!is_numeric($phone)) {
     $errMsg .= "<p>You must enter a number for your phone number.</p>";
 }
 if ($course == "") {
     $errMsg .= "<p>You must enter choose a course</p>";
 }
 if ($seats == "") {
     $errMsg .= "<p>You must enter how many seats you want to book.</p>";
 }