Skip to content

Instantly share code, notes, and snippets.

@marech
Last active August 29, 2015 14:21
Show Gist options
  • Save marech/65919239c80c7e6b8b5c to your computer and use it in GitHub Desktop.
Save marech/65919239c80c7e6b8b5c to your computer and use it in GitHub Desktop.
<?php
function parseStr($str){
//split multibyte chars
$chars = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
$r = '';
foreach ($chars as $i=>$char){
$r .= fixStr($char);
}
return $r;
}
function fixStr($char){
switch($char){
case 'Ā':
$char_code = 181;
break;
case 'ņ':
$char_code = 183;
break;
case 'ā':
$char_code = 198;
break;
case 'Š':
$char_code = 208;
break;
case 'š':
$char_code = 253;
break;
case 'č':
$char_code = 210;
break;
case 'Č':
$char_code = 211;
break;
case 'ģ':
$char_code = 214;
break;
case 'Ī':
$char_code = 215;
break;
case 'ī':
$char_code = 216;
break;
case 'ū':
$char_code = 221;
break;
case 'Ū':
$char_code = 222;
break;
case 'Ē':
$char_code = 240;
break;
case 'ē':
$char_code = 241;
break;
case 'Ģ':
$char_code = 242;
break;
case 'ķ':
$char_code = 243;
break;
case 'Ķ':
$char_code = 244;
break;
case 'ļ':
$char_code = 245;
break;
case 'Ļ':
$char_code = 246;
break;
case 'ž':
$char_code = 247;
break;
case 'Ž':
$char_code = 248;
break;
case 'Ņ':
$char_code = 252;
break;
default:
$char_code = ord($char);
}
return chr($char_code);
}
$res = parseStr('ēūīāšģķļžčņĒŪĪĀŠĢĶĻŽČŅ');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment