note 36373 added to ref.domxml

From: Date: Tue, 07 Oct 2003 19:41:45 +0000
Subject: note 36373 added to ref.domxml
Groups: php.notes 
Request: Send a blank email to php-notes+get-57977@lists.php.net to get a copy of this message
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(); ?> ---- Manual Page -- http://www.php.net/manual/en/ref.domxml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36373 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36373&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36373&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#57977) next »