I realize a search bar in my database. I explain I have two users in my database: "James Da" and "Paul Mo" I want that when the user searches for "James" this will show "James Da" but I also want that when he looks for "Da" it will show "James Da, and when he looks for just "ames", it will show "James Da" ...
My function only realizes the first case:
public function userSearch()
{
$users = [];
$request = Request::createFromGlobals();
$name = $request->query->get('name');
$directoryService = $this->get('etiam_nexus_directory.service.directory');
$localEstablishment = $directoryService->getLocalEstablishment();
$allUsers = $directoryService->getAllUsers($localEstablishment, $_GET);
for ($i = 0; $i <= count($allUsers); $i++) {
$user = $allUsers[$i];
if (substr(strtolower($user->getUserFullName()), 0, strlen($name)) === strtolower($name)) {
$users[] = '@' . $user->getUseruniqname() . ":server";
}
}
if(count($users) == 0) {
return JsonResponse::create(
array(
'success' => false,
'research' => $name
)
);
}
return JsonResponse::create(
array(
'success' => true,
'research' => array (
'name' => $users
)
)
);
}
Should I use another condition taking into account the space?