php - how to check if string in two different arrays match -
i check if string $value
in 2 different arrays match. if match, something. if don't match, something.
here code string value seperately if possible combine them , compare strings match.
here first lookup
$count = count($cert['tbscertificate']['subject']['rdnsequence']); $exists = array('utf8string', 'printablestring', 'teletexstring', 'bmpstring', 'universalstring', 'ia5string'); $oid = array('id-at-commonname'); for($i = 0; $i < $count; $i++) { foreach($exists $field) { if( array_key_exists($field, $cert['tbscertificate']['subject']['rdnsequence'][$i][0]['value']) && in_array($cert['tbscertificate']['subject']['rdnsequence'][$i][0]['type'], $oid) ) { $value = $cert['tbscertificate']['subject']['rdnsequence'][$i][0]['value'][$field]; echo $value; break; // stop further looping } } }
here second lookup:
$count = count($cert['tbscertificate']['issuer']['rdnsequence']); $exists = array('utf8string', 'printablestring', 'teletexstring', 'bmpstring', 'universalstring', 'ia5string'); $oid = array('id-at-commonname'); for($i = 0; $i < $count; $i++) { foreach($exists $field) { if( array_key_exists($field, $cert['tbscertificate']['issuer']['rdnsequence'][$i][0]['value']) && in_array($cert['tbscertificate']['issuer']['rdnsequence'][$i][0]['type'], $oid) ) { $value = $cert['tbscertificate']['issuer']['rdnsequence'][$i][0]['value'][$field]; echo $value; break; // stop further looping } } }
put lookup code in function takes type parameter, , returns value found. compare 2 calls.
function lookup($cert, $type) { $count = count($cert['tbscertificate'][$type]['rdnsequence']); $exists = array('utf8string', 'printablestring', 'teletexstring', 'bmpstring', 'universalstring', 'ia5string'); $oid = array('id-at-commonname'); for($i = 0; $i < $count; $i++) { foreach($exists $field) { if( array_key_exists($field, $cert['tbscertificate'][$type]['rdnsequence'][$i][0]['value']) && in_array($cert['tbscertificate'][$type]['rdnsequence'][$i][0]['type'], $oid) ) { $value = $cert['tbscertificate'][$type]['rdnsequence'][$i][0]['value'][$field]; return $value; } } } return null; } if (lookup($cert, 'subject') == lookup($cert, 'issuer')) { // }
Comments
Post a Comment