File: utf8.txt

package info (click to toggle)
php-net-ldap 1%3A1.1.5-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 496 kB
  • ctags: 1,120
  • sloc: php: 3,083; xml: 487; makefile: 3
file content (20 lines) | stat: -rw-r--r-- 745 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
UTF8 and Net_LDAP:

It is hard to know exactly what entries need utf8 every time you need them,
so here's the simple way to salvation:

Net_LDAP will check internally if utf8 is needed.

Code:
      // $attr is some text a user entered with funny characters in it.
      // If $attr should not be utfized (f.x. userPassword) then utf8Encode
      // will not encode the attribute.
      $attr = $ldap->utf8Encode($attr); 
      // now insert the correctly encoded attribute  into the directory.
      $entry->modify($attr);
      
      // later when you access the attributes of that user, decode the ones
      // that have to be decoded.
      $attr = $ldap->utf8Decode( $entry->attributes() );
                  
Thanks to Jan for the code.