Of course you probably want to see if it’s a Canadian Package or not:
Roughly something like the following?
[php]<?php
$name = ‘The Package is Expedited’; // Expedited needs to be replaced.
//function to validate postal code of canada
function validateCanadaZip($zip_code, $name)
{
/* Pattern(s) /
$patterns[0] = ‘Expedited’;
/ Replacement(s) /
$replacements[0] = ‘Canada Post’;
/ Check to see if it’s a Canadian Parcel */
if(preg_match("/^([a-ceghj-npr-tv-z]){1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}$/i",$zip_code))
{
return str_ireplace($patterns, $replacements, $name); // Change it if it is:
}
else
{
return $name; // Do nothing if it ain’t:
}
}
echo 'Unchange string : ’ . $name . “
\n”;
$result = validateCanadaZip(‘48150’, $name);
echo 'Trying it with a U.S. Zip Code ’ . $result . “
\n”;
$result = validateCanadaZip(‘A1B2c5’, $name);
echo 'Trying it with a Canadian Zip Code '. $result . “
\n”;
[/php]
It works, but of course not thoroughly tested and I am sure changes will have to made to fit your script(s).