Last active
November 4, 2023 22:58
-
-
Save szepeviktor/010211df28bce0c957bd3668a7a35b59 to your computer and use it in GitHub Desktop.
Határozott névelő hozzáadása egy szóhoz PHP-ban
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Grammar\Hungarian; | |
class DefiniteArticle | |
{ | |
const CONSONANTS = [ | |
'0', | |
'2', | |
'3', | |
'4', | |
'6', | |
'7', | |
'8', | |
'9', | |
'b', | |
'c', | |
'd', | |
'f', | |
'g', | |
'h', | |
'j', | |
'k', | |
'l', | |
'm', | |
'n', | |
'p', | |
'q', | |
'r', | |
's', | |
't', | |
'v', | |
'w', | |
'x', | |
'y', | |
'z', | |
]; | |
const ARTICLE_FOR_CONSONANTS = 'a'; | |
const ARTICLE_FOR_VOWELS = 'az'; | |
public static function artikulus(string $word): string | |
{ | |
$firstCharacter = mb_convert_case(mb_substr($word, 0, 1), MB_CASE_LOWER); | |
$article = in_array($firstCharacter, self::CONSONANTS) | |
? self::ARTICLE_FOR_CONSONANTS | |
: self::ARTICLE_FOR_VOWELS; | |
// 10-19 | |
if (preg_match('/^1[0-9]\b/', $word) === 1) { | |
$article = self::ARTICLE_FOR_CONSONANTS; | |
} | |
return sprintf('%s %s', $article, $word); | |
} | |
public static function artikulusSentence(string $word): string | |
{ | |
return ucfirst(self::artikulus($word)); | |
} | |
} |
Author
szepeviktor
commented
Nov 3, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment