note 36373 deleted from ref.domxml by sniper
| From: | sniper@php.net | Date: | Mon, 03 Nov 2003 15:46:38 +0000 |
| Subject: | note 36373 deleted from ref.domxml by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59702@lists.php.net to get a copy of this message | ||
Note Submitter: pookey@pookey.co.uk
----
LDAP to XML script - http://www.pookey.co.uk
<?php
$ldapServer = 'localhost';
$ldapBase = 'DC=anlx,DC=net';
/*
* try to connect to the server
*/
$ldapConn = ldap_connect($ldapServer);
if (!$ldapConn)
{
die('Cannot Connect to LDAP server');
}
/*
* bind anonymously
*/
$ldapBind = ldap_bind($ldapConn);
if (!$ldapBind)
{
die('Cannot Bind to LDAP server');
}
/*
* set the ldap options
*/
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
/*
* search the LDAP server
*/
$ldapSearch = ldap_search($ldapConn, $ldapBase, "(cn=*)");
$ldapResults = ldap_get_entries($ldapConn, $ldapSearch);
header('Content-type: text/xml');
$xmlRoot = domxml_new_doc("1.0");
$xmlContacts = $xmlRoot->create_element('contacts');
$xmlRoot->append_child($xmlContacts);
for ($item = 0; $item < $ldapResults['count']; $item++)
{
$xmlContact = $xmlRoot->create_element("contact");
for ($attribute = 0; $attribute < $ldapResults[$item]['count']; $attribute++)
{
$data = $ldapResults[$item][$attribute];
$xmlValues = $xmlRoot->create_element($data . 's');
for ($value = 0; $value < $ldapResults[$item][$data]['count']; $value++)
{
$xmlValue = $xmlRoot->create_element($data);
$xmlValueText = $xmlRoot->create_text_node($ldapResults[$item][$data][$value]);
$xmlValue->append_child($xmlValueText);
$xmlValues->append_child($xmlValue);
}
$xmlContact->append_child($xmlValues);
}
$xmlContacts->append_child($xmlContact);
}
echo $xmlRoot->dump_mem();
?>