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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -