public static function SimpleLdap::utf8encode in Simple LDAP 7
Same name and namespace in other branches
- 7.2 SimpleLdap.class.php \SimpleLdap::utf8encode()
UTF8-encode an attribute or array of attributes.
File
- ./SimpleLdap.class.php, line 83 
- Class defining base Simple LDAP functionallity.
Class
- SimpleLdap
- Simple LDAP class.
Code
public static function utf8encode($attributes) {
  // $attributes is expected to be an associative array.
  if (!is_array($attributes) || array_key_exists(0, $attributes)) {
    return FALSE;
  }
  // Make sure the schema is loaded.
  $this
    ->schema();
  // Loop through the given attributes.
  $utf8 = array();
  foreach ($attributes as $attribute => $value) {
    // Verify the schema entry for the current attribute is supposed to be
    // utf8 encoded. This is specified by a syntax OID of
    // 1.3.6.1.4.1.1466.115.121.1.15
    $attributetype = $this->schema
      ->get('attributetypes', $attribute);
    if (isset($attributetype['syntax']) && $attributetype['syntax'] == '1.3.6.1.4.1.1466.115.121.1.15') {
      $utf8[$attribute] = utf8_encode($value);
    }
    else {
      $utf8[$attribute] = $value;
    }
  }
  return $utf8;
}