note 36369 deleted from ref.domxml by joey

From: Date: Tue, 07 Oct 2003 19:36:41 +0000
Subject: note 36369 deleted from ref.domxml by joey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57976@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 = '81.91.100.18'; $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++) { $contact = $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); } //echo $data.":&nbsp;&nbsp;".$ldapResults[$item][$data][0]."<br>"; $contact->append_child($xmlValues); } $contacts->append_child($contact); } echo $xmlRoot->dump_mem(); ?>

« previous php.notes (#57976) next »