I have create preg_replace:
$searchTerm = preg_replace('/[^\p{L}\p{N}\s]/u', '', $searchTerm);
But when I search in search box this
!@#$%^&*()_+
it's not working.
I am expected When any one search this "!@#$%^&*()_+" then out put is "NO result Found".
Can any one suggest better preg_replace.
If you're trying to involve your regular expression with a database call, the searched value will have its content stripped of illegal characters and sent as an empty string to the database (where no results will be found):
$searchTerm = '!@#$%^&*()_+';
$searchTerm = preg_replace('/[^\p{L}\p{N}\s]/u', '', $searchTerm);
// $searchTerm = '';
// Send this off to DB (which will return false)
if (!$search->search_db($searchTerm)) {
echo 'No search results!';
}
If you don't want it to touch a DB, you can just keep it within the scope of the current script:
if (preg_match('/[^\p{L}\p{N}\s]/u', $searchTerm)) {
echo 'No search results!';
}