Core\Ldap\Filter::startsWith
Core\Ldap\Filter::startsWith(
string $attribute,
string $value,
): Core\Ldap\FilterBuilds a filter that finds the directory entries where a value of an attribute starts with this text.
Use it for a search box that shows matches while a person types, or to find every account whose name starts with the same letters. The text is sent to the server as data. A * in it is a normal character and not a wildcard, so a value from a form cannot widen the search.
An empty text throws a LogicError. To find every entry that has the attribute at all, use Core\Ldap\Filter::present. A name with a character that an attribute name cannot have throws a LogicError too.
Parameters
$attributestringThe attribute's name, such assAMAccountName. It cannot betainted.$valuestringThe text to look for. It may betainted. A*in it is a normal character, and not a wildcard.
Return value
Returns Core\Ldap\Filter. A Core\Ldap\Filter.
Errors
LogicError$attributeis not an attribute name, or$valueis empty.
Examples
Search while typing
<?nvs// Shows how to find the people whose name starts with what somebody typed so far.
string $typed = 'An';var $filter = Core\Ldap\Filter::startsWith('displayName', $typed);// This prints (displayName=An*).echo $filter->toString(), "\n";(displayName=An*)Only user accounts
<?nvs// Shows how to find the user accounts whose login name starts with `svc-`.
var $filter = Core\Ldap\Filter::all( Core\Ldap\Filter::equals('objectClass', 'user'), Core\Ldap\Filter::startsWith('sAMAccountName', 'svc-'),);// This prints (&(objectClass=user)(sAMAccountName=svc-*)).echo $filter->toString(), "\n";(&(objectClass=user)(sAMAccountName=svc-*))Empty text
<?nvs// Shows what happens when the text to look for is empty.
string $typed = '';try { Core\Ldap\Filter::startsWith('displayName', $typed);} catch (LogicError $error) { // An empty text throws an error. `present` finds every entry with a value. echo "Nothing typed yet.\n"; echo Core\Ldap\Filter::present('displayName')->toString(), "\n";}Nothing typed yet.(displayName=*)