Jump to content
php.lv forumi

Recommended Posts

Posted

Labdien!

Mani interesē, vai pastāv iespēja, tekstu, kas ir latviešu valodā pārveidot uz standarta latīņu alfabēta tekstu - tipa vai nu izņemt burtus, kuros ir garumzīmes / mīkstinājuma zīmes vispār ārā, vai noņemt garumzīmi/ mīkstinājuma zīmi. Mēģināju to panākt ar šādu funkciju, taču aplauzos - tas laikam nav īstais ... :(

<?php
function charset_decode_utf_8($string) 
{  
	if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string)) 
	return $string; 
	$string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",		
	"''.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",	
	$string); 
	$string = preg_replace("/([\300-\337])([\200-\277])/e", 
	"''.((ord('\\1')-192)*64+(ord('\\2')-128)).';'", 
	$string); 
	return $string; 
}
?>

Vai kāds ir kautko tamlīdzīgu taisījis?

Posted (edited)

echo iconv('UTF-8','ASCII//TRANSLIT','glāžšķūņu rūķīši');// izvada - glazskunu rukisi

Protams, ja teksts ir utf8

Edited by xPtv45z
Posted

To vajag darīt ar parastu str_replace vai strtr.

Saraksti masīvu ar ko uz ko konvertēt ("ā" => "a", "č" => "č", utt) un izsauc attiecīgo fju.

Posted

sliņķiem RU & LV

 

function translitString($str) {
$str = str_replace(array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю','Ā','Č','Ē','Ģ','Ī','Ķ','Ļ','Ņ','Š','Ū','Ž', 'ā','č','ē','ģ','ī','ķ','ļ','ņ','š','ū','ž'),array('A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z','i','c','u','k','e','n','g','sh','sh','z','h','i','f','i','v','a','p','r','o','l','d','zh','e','ja','ch','s','m','i','t','','b','ju','I','C','U','K','E','N','G','SH','SH','Z','H','I','F','I','V','A','P','R','O','L','D','ZH','E','JA','CH','S','M','I','T','','B','JU','A','C','E','G','I','K','L','N','S','U','Z','a','c','e','g','i','k','l','n','s','u','z'),$str);
return $str;
}

  • 3 weeks later...
Posted (edited)

Sadarbojoties ar citvalodīgajiem, nākas sūtīt viņiem datu failus kuros ir Latvijas adreses un kuros drīkst būt tikai latīņu burti un vēl nedrīkst būt specsimboli, tad nu izmantoju:

$LATV=array("ā","Ā","č","Č","ē","Ē","ģ","Ģ","ī","Ī","ķ","Ķ","ļ","Ļ","ņ","Ņ","š","Š","ū","Ū","ž","Ž",".",'"',"   ","-","_","/"); //Latviešu garie un mīkste burti un neatļautie simboli
$LATIN=array("a","A","c","C","e","E","g","G","i","I","k","K","l","L","n","N","s","S","u","U","z","Z","",""," ",""," "," "); //Latviešu mīksto un garo burtu un neatļauto simbolu aizstāēji
$IELA_LATIN=str_replace($LATV,$LATIN,$IELA_LATV); //Latviešu garos un mīkstos burtus aizstāj ar latīņu burtiem

Edited by Ranny

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...