This question already has an answer here:
I'm having trouble understanding the logic in the regular expression inside the preg_replace function. Specifically, I'm having trouble understanding the use of the caret inside the brackets. If I type a single letter/number that matches any letter/number in the username column, I'll get a match for that row. When I remove the caret, even when I don't search for anything, everything in my db matches. Can someone please elaborate on what's going on here? Thanks.
$searchq = $_POST['search'];
$searchq = preg_replace("/[^0-9a-z]/i","",$searchq );
$query = mysqli_query($conn, "SELECT * FROM people ".
"WHERE username LIKE '%$searchq%'") or die('Could not search.');
</div>