Skip to content

Core\Ldap\Dn::rdnValue

$dn->rdnValue(): tainted string

Returns the value of the first part of a DN, with its escapes removed. For CN=Lee\, Ann,OU=Staff,DC=example,DC=test the result is Lee, Ann.

Use it to show the name of an entry, such as a person's name or a group's name.

Good to know: the result is tainted, because the value can come from the server or from user input. When the first part has several values joined by +, the result is the first one.

Return value

Returns tainted string. The value. It is tainted. When the first part has several values joined by +, it is the first one.

Examples

A name

<?nvs
// Shows how to read the name of an entry from its DN.
var $person = Core\Ldap\Dn::parse('CN=Ann Lee,OU=Staff,DC=example,DC=test');
// This prints Ann Lee.
echo $person->rdnValue(), "\n";
Output
Ann Lee

Escapes are removed

<?nvs
// Shows that the value is returned without its escapes.
var $person = Core\Ldap\Dn::of('DC', 'test')->child('CN', 'Lee, Ann');
// The text has an escaped comma. This prints CN=Lee\, Ann,DC=test.
echo $person->toString(), "\n";
// The value does not. This prints Lee, Ann.
echo $person->rdnValue(), "\n";
Output
CN=Lee\, Ann,DC=test
Lee, Ann

Several values

<?nvs
// Shows the result when the first part has two values joined by `+`.
var $person = Core\Ldap\Dn::parse('CN=Ann+UID=ann7,OU=Staff,DC=example,DC=test');
// The result is the first value. This prints Ann.
echo $person->rdnValue(), "\n";
Output
Ann