Im creating a socialnetwork, and this script is a search function.
$username = $_SESSION['username'];
$search = $_POST['search'];
//strpos($user,$search)
$path = "../database/users";
$users = scandir($path);
$output = array();
$count = 0;
foreach($users as $user) {
if ("$user" !== ".." || "$user" !== "." | "$user" !== "$username") {
if(strpos($user, $search)) {
$count = $count + 1;
array_push($output, $user);
}
}
}
Now im wondering why it gives me just 1 value in the output array... wenn there are more users with the a in it (it gives me none output when i search for more than one).
strpos might return 0, which is valid (means the string starts with the search phrase), but it will not pass the if(strpos($user, $search))
check.
Consider adding if(strpos($user, $search) !== false)
.
Also remove the bitwise or |
and replace it with a logical or ||
.