Be kind... I just got back from 15 hours of driving, I left my computer in FL, took someone else's by accident, and wrote this in Notepad with severely bad internet connection (storms I presume).
@Spuds, can you give this a shot? I think it will work. I think you'll understand how it should be placed in Subs.php. I just took the example from that book and it looks like it will fit perfectly. It does a check per permutation instead of getting them all before.
function pc_next_permutation($p, $size) {
// slide down the array looking for where we're smaller than the next guy
for ($i = $size - 1; $p[$i] >= $p[$i+1]; --$i) { }
// if this doesn't occur, we've finished our permutations
// the array is reversed: (1, 2, 3, 4) => (4, 3, 2, 1)
if ($i == -1) { return false; }
// slide down the array looking for a bigger number than what we found before
for ($j = $size; $p[$j] <= $p[$i]; --$j) { }
// swap them
$tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
// now reverse the elements in between by swapping the ends
for (++$i, $j = $size; $i < $j; ++$i, --$j) {
$tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
}
return $p;
}
$set = array();
foreach ($possible['parameters'] as $p => $info)
{
$set[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . ')' . (empty($info['optional']) ? '' : '?');
}
$size = count($set) - 1;
$keys = range(0, $size);
$message_part = substr($message, $pos1 - 1);
do {
$match_string = '~^';
foreach ($keys as $key)
{
$match_string .= $set[$key];
}
$match_string .= '\]~i';
$match = preg_match($match_string, $message_part), $matches) != 0;
} while (!$match && ($keys = pc_next_permutation($keys, $size)));