note 50114 added to function.ldap-dn2ufn
| From: | naaina at gmail dot com | Date: | Fri, 18 Feb 2005 12:18:56 +0000 |
| Subject: | note 50114 added to function.ldap-dn2ufn | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85207@lists.php.net to get a copy of this message | ||
Don't know if anyone is interested in this, but this is a modified and more dynamic version of
the posting below. Since ldap_dn2ufn takes ',' as delimiter for the UFNs, we'll also
use it here. $pHowToBuild specifies, how the DN is going to be build.
Short example:
$myUFN = ldap_dn2ufn("cn=naaina, ou=container1, ou=container2, ou=container3, o=private,
c=de");
echo $myUFN . "\n"; // will return "naaina, container1, container2, container3,
private, de"
$myDN = $ldapObject->conv_ufn2dn($myUFN);
echo $myDN . "\n"; // will return
"cn=naaina,ou=container1,ou=container2,ou=container3,o=private,c=de"
For the object name, $pHowToBuild["object"] is going to be used as prefix - for containers
$pHowToBuild["container"] and for the last n elements $pHowToBuild["last"].
<?php
function ldap_ufn2dn (
$pUFN,
$pDelimiter = ",",
$pHowToBuild = array(
"object" => "cn",
"container" => "ou",
"last" => array("o", "c")
)
)
{
$resultDN = null;
if(!empty($pUFN)) {
/* Check $pHowToBuild */
if(is_array($pHowToBuild)) {
/* Check if required keys are existent */
if(array_key_exists("object", $pHowToBuild) &&
array_key_exists("container", $pHowToBuild) &&
array_key_exists("last", $pHowToBuild))
{
$ufnArray = explode($pDelimiter, $pUFN);
$ufnLast = count($ufnArray) - count($pHowToBuild["last"]);
/* Remove empty values */
foreach($ufnArray as $objKey => $objVal)
if(empty($objVal))
array_splice($ufnArray, $objKey, 1);
/* Now build the DN ... */
foreach($ufnArray as $objKey => $objVal) {
$objVal = trim($objVal);
if($objKey == 0) {
/* For the object */
$resultDN .= $pHowToBuild["object"] . "=" . $objVal .
",";
} elseif ($objKey >= $ufnLast) {
/* For last parts of the DN */
$resultDN .= $pHowToBuild["last"][$objKey - $ufnLast] . "=" .
$objVal;
if(($objKey - $ufnLast - 1) != 0) {
$resultDN .= ",";
}
} else {
/* For containers */
$resultDN .= $pHowToBuild["container"] . "=" . $objVal .
",";
}
}
}
}
}
return $resultDN;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.ldap-dn2ufn.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50114
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50114&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50114&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50114&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50114&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50114&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50114&report=yes
Search -- http://master.php.net/manage/user-notes.php