Probably not the best way but for those who are looking for a way to get de CN of a DN without the "cn=" part this is a function with a regex pattern:
<?php
function getCNofDN($dn) {
$return=preg_match('/[^cn=]([^,]*)/i',$dn,$dn);
return($dn[0]);
}
echo getCNofDN("cn=emepese,cn=someLevel,dc=someCompany");
// Will print "emepese"
?>