Skip to content

Instantly share code, notes, and snippets.

@evikza
Last active June 12, 2022 17:41
Show Gist options
  • Select an option

  • Save evikza/da6c7cab98a87865afa1f83287c5184f to your computer and use it in GitHub Desktop.

Select an option

Save evikza/da6c7cab98a87865afa1f83287c5184f to your computer and use it in GitHub Desktop.
<?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