Forum Moderators: coopster
My script 'reads' email messages and takes action based upon certain fields. An example of this would be a line in the email that reads: FDC Authorization Code: 9999999, and my script will parse that string and then do a test for 'FDC Authorization Code'. Fine and dandy, until the format of the message gets changed. Suddenly, results are unexpected and or simply not forthcoming at all. In this example the line in question was changed to 'FDC AuthCode'.
There were at least 4 changes like this made to the email that I process. One of those changes was a show-stopper. Using the same example I changed my test to "FDC Auth" so I could capture both, but this isn't possible with every change. The other thing I did was to convert all of my checks to UPPERCASE. The show-stopper was a case of changing the word Email to EMail. Arrgh!
There must be a better way!
Do you have to deal with this sort of problem or have you got a sure-fire way to minimize problems of this nature?
function get_FDC_code($text)
{
$matches = array();
$pattern = "/(FDC)\s?(Auth)(oriz?s?ation)?\s?(code):\s?([0-9]+)/i";
preg_match($pattern, $line, $matches);
return $matches;
}
$resultArray = get_FDC_code($text);
$authCode = $resultArray[5];
// Valid matches:
// FDC AuthCode: 2398348
// FDC Authorization Code: 23492348
// FDCauthcode: 3434
// Uncomment this line if you want to see all matches
// And their array keys
// print_r($resultArray);
What method were you using to validate it?
$temp = (substr($val,0,12));
$temp = strtoupper($temp);
if ($temp == "EXPRESS MAIL") {
//
}
If you need some regex's just post what data you need to check for and I can try and write the patterns for you.
(I'm using 'check' and 'validate' interchangeably... sorry if I wasn't clear before. I just meant the checks that you using to make sure you were reading the data you were expecting)