0

I am trying to use preg_replace function and it works as expected. The problem is it also removes the special alphabet like this one Ö and removes O. How can I keep Ö?

$string='GÖTEBORG-SEASON-1';
echo $str=preg_replace('/[^A-Za-z-_]/', '', $string);

It output GTEBORG-SEASON- (Ö is missing) but I am expecting GÖTEBORG-SEASON-

Thank you.

Hkm Sadek
  • 2,987
  • 9
  • 43
  • 95
  • 1
    Is every string you want to replace like this? Because then, you could just use `substr()` and only remove the last character. Else `preg_replace('/\d/', '', $string);` comes to mind if you only want to remove digits. Please be more clear what you want to achieve. – Loek Jun 06 '18 at 09:14
  • Does this also happen when you use the RegExp ``'/[^A-Za-z_-]/'``? – allo Jun 06 '18 at 09:18
  • Use [mb_ereg_replace](http://php.net/manual/en/function.mb-ereg-replace.php) with multibyte support. – Michel Jun 06 '18 at 09:19

1 Answers1

0

I think I have solved it. I need to use something like this preg_replace ('/[^\p{L}-_]/u','', $string);

Hkm Sadek
  • 2,987
  • 9
  • 43
  • 95