fork download
  1. <?php
  2. // English:
  3. $testString = "The classical Latin alphabet, also known as the Roman alphabet, is a writing system originally used by the ancient Romans to write the Latin language. The Latin alphabet evolved from the visually similar Cumaean Greek version of the Greek alphabet, which was itself descended from the Phoenician abjad, which in turn was derived from Egyptian hieroglyphics.[1] The Etruscans who ruled early Rome adopted the Cumaean Greek alphabet which was modified over time to become the Etruscan alphabet, which was in turn adopted and further modified by the Romans to produce the Latin alphabet. During the Middle Ages the Latin alphabet was used (sometimes with modifications) for writing Romance languages, direct descendants of Latin, as well as Celtic, Germanic, Baltic, and some Slavic languages. With the age of colonialism and Christian evangelism, the Latin script spread beyond Europe, coming into use for writing indigenous American, Australian, Austronesian, Austroasiatic, and African languages. More recently, linguists have also tended to prefer the Latin script or the International Phonetic Alphabet (itself largely based on Latin script) when transcribing or creating written standards for non-European languages, such as the African reference alphabet. The term Latin alphabet may refer to either the alphabet used to write Latin (as described in this article), or other alphabets based on the Latin script, which is the basic set of letters common to the various alphabets descended from the classical Latin alphabet, such as the English alphabet. These Latin alphabets may discard letters, like the Rotokas alphabet, or add new letters, like the Danish and Norwegian alphabets. Letter shapes have evolved over the centuries, including the creation for Medieval Latin of lower-case forms which did not exist in the Classical period alphabet.";
  4.  
  5. // German:
  6. //$testString = "Das lateinische Alphabet ist ursprünglich das zur Schreibung der lateinischen Sprache verwendete Alphabet; es wird in diesem Zusammenhang auch römisches Alphabet genannt. Es umfasst 26 Buchstaben und bildet die Grundlage vieler heutiger Alphabete. Zusammen bilden diese „lateinischen Alphabete“ das lateinische Schriftsystem, das am weitesten verbreitete Schriftsystem der Welt. Einige Sprachen wie beispielsweise das Englische benutzen das Alphabet ohne Veränderungen. Das lateinische Alphabet stammt vom altitalischen Alphabet der Etrusker ab, von denen die Römer zunächst 21 Buchstaben übernahmen. Zur Zeit des klassischen Lateins und in der Spätantike bestand das Alphabet aus 23 Buchstaben. Die Zahl von 26 Buchstaben wurde erst in der Renaissance erreicht. Einige Buchstaben wichen von diesem Schema ab: K und Q bilden den Namen mit dem für sie typischen Vokal: ka, qu (zur Verdeutlichung des Unterschiedes zu ce für C). X wurde ex genannt, Z wurde mit dem griechischen Namen zeta bezeichnet. Für Y gab es verschiedene Namen, darunter i Graeca („griechisches i“). Bröhl studierte Rechtswissenschaft an den Universitäten Tübingen, Freiburg, München und Bonn. Im März 1971 legte er im Oberlandesgerichtsbezirk Köln das Zweite Juristische Staatsexamen ab und trat kurz darauf in den höheren Justizdienst des Landes Nordrhein-Westfalen ein. Dort war Bröhl zunächst als Richter beim Arbeitsgericht Köln tätig. Im September 1980 wurde er zum Vorsitzenden Richter am Landesarbeitsgericht Düsseldorf ernannt. Ab 1985 war er am Landesarbeitsgericht Köln tätig.";
  7.  
  8. $common_english_words = array('time', 'person', 'year', 'way', 'day', 'thing', 'man', 'world', 'life', 'hand', 'part', 'child', 'eye', 'woman', 'place', 'work', 'week', 'case', 'point', 'government', 'company', 'number', 'group', 'problem', 'fact', 'be', 'have', 'do', 'say', 'get', 'make', 'go', 'know', 'take', 'see', 'come', 'think', 'look', 'want', 'give', 'use', 'find', 'tell', 'ask', 'seem', 'feel', 'try', 'leave', 'call', 'good', 'new', 'first', 'last', 'long', 'great', 'little', 'own', 'other', 'old', 'right', 'big', 'high', 'different', 'small', 'large', 'next', 'early', 'young', 'important', 'few', 'public', 'bad', 'same', 'able', 'to', 'of', 'in', 'for', 'on', 'with', 'at', 'by', 'from', 'up', 'about', 'into', 'over', 'after', 'beneath', 'under', 'above', 'the', 'and', 'a', 'that', 'i', 'it', 'not', 'he', 'as', 'you', 'this', 'but', 'his', 'they', 'her', 'she', 'or', 'an', 'will', 'my', 'one', 'all', 'would', 'there', 'their', 'I', 'we', 'what', 'so', 'out', 'if', 'who', 'which', 'me', 'when', 'can', 'like', 'no', 'just', 'him', 'people', 'your', 'some', 'could', 'them', 'than', 'then', 'now', 'only', 'its', 'also', 'back', 'two', 'how', 'our', 'well', 'even', 'because', 'any', 'these', 'most', 'us');
  9.  
  10. //$transformedTest = preg_replace("@('s|s')@", '', preg_replace('@(\s{2,}|\S+)@', ' ', preg_replace("@[^a-zA-Z'\s]@", ' ', strtolower($testString))));
  11. $transformedTest = preg_replace('@\s+@', ' ', preg_replace("@[^a-zA-Z'\s]@", ' ', strtolower($testString)));
  12.  
  13. $splitTest = explode(' ', $transformedTest);
  14.  
  15. $matchCount = 0;
  16. for($i=0;$i<count($splitTest);$i++){
  17. if(in_array($splitTest[$i], $common_english_words))
  18. $matchCount++;
  19. }
  20.  
  21. echo "raw count: $matchCount\n<br>\nPercent: " . ($matchCount/count($common_english_words))*100 . "%\n<br>\n";
  22. if(($matchCount/count($common_english_words)) > 0.5){
  23. echo "More than half of the test string is English. Text is likely English.";
  24. }else{
  25. echo "Text is likely a foreign language.";
  26. }
  27. ?>
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
raw count: 106
<br>
Percent: 69.281045751634%
<br>
More than half of the test string is English. Text is likely English.