Created
March 27, 2022 11:43
-
-
Save muratcakmaksoftware/b82267dc92f97663ee0e480431dcb579 to your computer and use it in GitHub Desktop.
PHP ile Türkiye'nin plaka regex kontrolü ve açıklamalarıyla beraber.
This file contains hidden or 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 | |
//https://www.phpliveregex.com/ //testin yapılması | |
//wiki baz alındı: https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Turkey | |
$GLOBALS['regexPlate1'] = "/\b\d{2}\W[A-Z]{1,3}\W\d{2,5}\b/"; // 99 X 99 ~ 99 XXX 99999 | |
$GLOBALS['regexPlate2'] = "/\b\d{2}[a-zA-Z]{1,3}\d{2,5}\b/"; // 99X99 ~ 99XXX99999 | |
/* | |
\b kelime sınırlama | |
\d sayı | |
\W kelime olmayan karakter -_* gibi | |
\[a-zA-Z] büyük küçük latin harf | |
\{0,3} adet aralığı belirlenmesi | |
* */ | |
/** | |
* @param string $plate | |
* @return boolean | |
*/ | |
function turkishPlateSearch($plate) | |
{ | |
$matches = []; | |
preg_match($GLOBALS['regexPlate1'], $plate, $matches); | |
return count($matches) > 0 ? true : false; | |
} | |
echo turkishPlateSearch("99 A 99"). "<br/>"; | |
echo turkishPlateSearch("99 AAA 9999"). "<br/>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment