The function of bryan will only work if you start with an Organization and using only an Organizational Unit as a container and the object is an CN.
For example:
$DN = "CN=DNS,CN=Authorized Login Methods,CN=Security";
echo ($DN = ldap_dn2ufn($DN)) . "\n";
echo ($DN = ldap_ufn2dn($DN)) . "\n";
will echo:
DNS,Authorized Login Methods,Security
CN=DNS,OU=Authorized Login Methods,O=Security