Skip to main content
WolfShade
Legend
May 10, 2013
Question

CF9 - convert LDAP data into associative array?

  • May 10, 2013
  • 1 reply
  • 924 views

Hello, everyone.

Does anyone have any suggestions on a good way to convert LDAP data into an associative array with the key being the fieldname?

For example:

dn: CN=First Last, OU=Dept A, OU=Dept B, OU=Domain Users,DC=hq,DC=domainname,DC=com

changetype: edit

sn: Last

description: Dept C

telephoneNumber: xxx-xxx-xxxx

givenName: First

empID: ab1234x

mail: Last.First@domainname.com

There are several thousand similar to the above; some will have three lines of data, some as many as twelve, each individual separated by double line breaks (<br />).  I need to make an array where "dn", "changetype", "sn", etc., are the keys with the text after the colon as the value.

What is the best way to do this?

Thank you,

^_^

    This topic has been closed for replies.

    1 reply

    12Robots
    Participating Frequently
    May 10, 2013

    What is the source of the data?  Is it a text file with the above data?  Is it an LDAP query?  Spreadsheet?

    Jason

    WolfShade
    WolfShadeAuthor
    Legend
    May 10, 2013

    Hi, Jason.

    Sorry.. I still haven't completely woken up, yet. 

    The data is in a .ldf file that resides on the server.  Right now, I'm using CFFILE to read it into a string.  I can also set it up for JavaScript, if that would be easier/quicker/more efficient.

    ^_^

    WolfShade
    WolfShadeAuthor
    Legend
    May 10, 2013

    Well.. I pushed ahead, a little, and am trying to manually create an array of arrays.  But the nested array is (at least, what I _plan_ for it to be) an associative array.  So I'm splitting on the colon ":" and trying to set the left value as the key and the right value as the value.

    But I'm getting an error message: The value Dn cannot be converted to a number.

    I've tried many things, including ToString, and I just can't seem to nail it.

    ^_^