2

I am sanitizing a query using the following regex. However, I need some special characters to be allowed in the query.

In particular I need to allow: Ä, ä, Ö, ö, Ü, ü, ß

What do I need to change to achieve this?

$query = preg_replace('/[^-a-zA-Z0-9_\/]/', '', $_GET['destination']);
maze
  • 137
  • 2
  • 7

2 Answers2

4
/[^\w-\p{L}\p{N}\p{Pd}]/

This will match anything that's NOT an alphanumeric character (including UTF-8 letters) as well as the dash (-).

bcosca
  • 17,371
  • 5
  • 40
  • 51
2

Your question is really about how to support multibyte characters in preg expressions, see:

Community
  • 1
  • 1
Hamish
  • 22,860
  • 8
  • 53
  • 67