Skip to content

Instantly share code, notes, and snippets.

@giventofly
Last active May 1, 2024 07:37
Show Gist options
  • Save giventofly/315b4d0ce21606e4b582553aba1bc3a4 to your computer and use it in GitHub Desktop.
Save giventofly/315b4d0ce21606e4b582553aba1bc3a4 to your computer and use it in GitHub Desktop.
regex convert russian (cyrillic) to latin
<?php
//https://stackoverflow.com/a/6837426/1911609
function strtolatin($string){
if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false){
$string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8');
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment