0

I need to know if the given string is in German, Indian or Persian.

Checking for Lating or non-Latin, I simply use [a-zA-Z] regExp, but I don't know what should I do when I have two non-Latins and a German language.

Do we have any character-range other than [a-zA-Z], maybe with code range, if exists at all.

Something like this:

$string = "MyCharactersInGermanlanguage";

$res = preg_match("/[characterRangeOfgermanLanguage]/", $string);

Thanks in advanced.

Mostafa Talebi
  • 8,825
  • 16
  • 61
  • 105

2 Answers2

1

Have you looked at the unicode support?

http://php.net/manual/en/regexp.reference.unicode.php

You might also want to look here for ways to detect the language from the string:

Detect language from string in PHP

Community
  • 1
  • 1
Rachael
  • 424
  • 2
  • 7
0

The full set of german letters:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäÄöÖüÜß


The php regex to match the characters is:

[A-Za-z\xC4\xD6\xDC\xDF\xE4\xF6\xFC]+
Andie2302
  • 4,825
  • 4
  • 24
  • 43