October 22, 2024
Chicago 12, Melborne City, USA
PHP

Why does PHP preg_replace() not propery replace “µ” in string?


I got this string:

"Grünkohl (gegart) [vom Bauern, -50% gewaschen([{vBü,_-4%?+#*^°\ß´`&§"!<>|'~.:,;µ{}/$²³}])"

I want to have all characters except some allowed ones replaced by "-".

This is my function call:

preg_replace('/[^a-z0-9äöü°!"²§³\\$&\\(\\[\\)\\]=ß´\\+\\*~\'\\-_\\.:\\,;<>@€]/i', '-', $string);

And this is the string I get:

"Grünkohl-(gegart)-[vom-Bauern,--50--gewaschen([-vBü,_-4--+-*-°-ß´-&§"!<>-'~.:,;�----$²³-])"

Why is the "µ" not propery replaced? (it turned to "�-")



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video