php - preg_replace: replace everything but -
i want remove unwanted characters following string. here's code.
$input="aecąßÄ1,.!?-_'\"/><"; $input=preg_replace('/[^\p{p}\p{l}\p{n}\s]*/u', '', $input);
the code seems working fine special characters lost in output. here's get.
aec���1,.!?-_'"/
instead of
aecąßÄ1,.!?-_'"/
why so?
edit based on comment:
try use "real" characters:
$input= preg_replace('/[^aecąßÄ1,.!?-_\'\"\/]/', '', $input);
last answer:
if want remove unwanted characters, can remove characters simpler regex:
$input= "aecąßÄ1,.!?-_'\"/><"; $input= preg_replace('/[<>]/', '', $input);
just put special characters between [ ] in regex. works in case.
Comments
Post a Comment