Last active
June 12, 2022 17:41
-
-
Save evikza/da6c7cab98a87865afa1f83287c5184f to your computer and use it in GitHub Desktop.
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 | |
| function replace_area_format(string $area): string | |
| { | |
| $pattern = [ | |
| '/\bсот(к[а|и]|ок)\b/ui' => 'сот.', | |
| '/\b(гектар)(|[ы]|(а|ов))\b/ui' => 'Га', | |
| '/\b(кв(.\s?)м)(|етр)(|ов|а)\b/ui' => 'м²', | |
| ]; | |
| foreach ($pattern as $regex => $iterator) { | |
| $entrance = preg_match($regex, $area); | |
| if ($entrance) { | |
| $area = preg_replace($regex, $iterator, $area); | |
| break; | |
| } | |
| } | |
| return $area; | |
| } | |
| echo replace_area_format('кв. м'); // м² |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment