preg_replace: replace everything but
I want to remove some unwanted characters from the following string. Here's the code.
$input="aecąßÄ1,.!?-_'\"/><";
$input=preg_replace('/[^\p{P}\p{L}\p{N}\s]*/u', '', $input);
The code seems to be working fine but the special characters are lost in the output. Here's what 开发者_运维知识库I get.
aec���1,.!?-_'"/
Instead of
aecąßÄ1,.!?-_'"/
Why is it so?
EDIT based on comment:
Try to use "real" characters:
$input= preg_replace('/[^aecąßÄ1,.!?-_\'\"\/]/', '', $input);
last answer:
If you want to remove unwanted characters, you can remove that characters with much simpler regex:
$input= "aecąßÄ1,.!?-_'\"/><";
$input= preg_replace('/[<>]/', '', $input);
Just put that special characters between [ ] in regex. This will works in your case.
精彩评论