Use the mb_ereg_replace, preg_replace with multibyte support
preg_replace everything but alpha numeric and accents
-
01-07-2022 - |
题
Been searching for a while , but as I do not understand the preg-replace parameters that can be entered, I can't solve my problem by looking at similar questions. (therefore I would like to ask that you could explain each sign in your answer?)
I want to filter a string and replace everything that is not alphanumeric or an accent with a space. (After this I use preg_split to make a list of them).
Under here the symbols I known as accents, showed only the lower-case, but want to keep the upper-case variants too.(might have forgotten a few). I really need the left signs. The right are not obligatory:
é è ë ï ê ç ü ö ä ú ó á ã õ ñ å û â ô
I need this because I have to search my database(prepared statements) for it.
Currently I use:
$terms=preg_split('/\s+/', preg_replace('/[^a-zA-Z0-9À-ÿ]+/', ' ', $_GET['ter']));
But the following example shows that it does not leave the signs as they are:
url example: mydomain.com/index.php?ter=léopold
$terms=preg_split('/\s+/', preg_replace('/[^a-zA-Z0-9À-ÿ]+/', ' ', $_GET['ter']));
foreach ($erms as $term){echo " term: ".$term;}
Outputs:
term: l� term: opold
What i want it to be:
term: léopold
So I need to create a preg_replace that does not harm the accents ,especially the ones written on the left in the first code-block
解决方案