In my googlings for 'PHP DIGEST-MD5' I've come across a patch for another project that deals with the same format string with the folowing line:
preg_match_all('/(\w+)=(?:"([^"]*)|([^,]*))/', $challenge, $matches);
Which gives me:
array (
0 =>
array (
0 => 'realm="smtp.domain.net',
1 => 'nonce="AJRUc5Jx0UQbv5SJ9FoyUnaZpqZIHDhLTU+Awn/K0Uw=',
2 => 'qop="auth,auth-int',
3 => 'charset=utf-8',
4 => 'algorithm=md5-sess',
),
1 =>
array (
0 => 'realm',
1 => 'nonce',
2 => 'qop',
3 => 'charset',
4 => 'algorithm',
),
2 =>
array (
0 => 'smtp.domain.net',
1 => 'AJRUc5Jx0UQbv5SJ9FoyUnaZpqZIHDhLTU+Awn/K0Uw=',
2 => 'auth,auth-int',
3 => '',
4 => '',
),
3 =>
array (
0 => '',
1 => '',
2 => '',
3 => 'utf-8',
4 => 'md5-sess',
),
)
Then I can fill out a useful array with this loop:
$authvars = array();
foreach( $auth_matches[1] as $key => $val ) {
if( !empty($auth_matches[2][$key]) ) {
$authvars[$val] = $auth_matches[2][$key];
} else {
$authvars[$val] = $auth_matches[3][$key];
}
}
Which gives me:
array (
'realm' => 'ns103.zabco.net',
'nonce' => 'xITX1qgqlCDmYX6IrctN0WZRx7+Q4W7jjaXCCeUZnU8=',
'qop' => 'auth,auth-int',
'charset' => 'utf-8',
'algorithm' => 'md5-sess',
)
It's not exactly pretty, but it gets the job done.