File: utf8.txt

package info (click to toggle)
php-net-ldap2 2.0.12-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 676 kB
  • ctags: 1,474
  • sloc: php: 3,583; xml: 800; makefile: 5
file content (20 lines) | stat: -rw-r--r-- 747 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
UTF8 and Net_LDAP2:

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

Net_LDAP2 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.