Jump to content
php.lv forumi

lv burtu maiņa


yeahz

Recommended Posts

    $lv_burti = array("ē", "ŗ", "ū", "ī", "ō", "ā", "š", "ģ", "ķ", "ļ", "ž", "č", "ņ");
   $eng_burti = array("e", "r", "u", "i", "o", "a", "s", "g", "k", "l", "z", "c", "n");
   $title = str_replace($lv_burti, $eng_burti, $title);

Tie burti netiek nomainīti no garumzīmjveidīgajiem pret bezgarumzīmjveidīgajiem. Kāpēc?

Link to comment
Share on other sites

Izmanto šo:

function getSeo($str, $separator = '-'){
$str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
$str = trim(preg_replace('/[^ A-Za-z0-9_-]/', ' ', $str));
return preg_replace('/[ -]+/', $separator, $str);
}

 

 

Hz, kas tev tur, bet man strādā:

 

$lv_burti = array("ē", "ŗ", "ū", "ī", "ō", "ā", "š", "ģ", "ķ", "ļ", "ž", "č", "ņ");

$eng_burti = array("e", "r", "u", "i", "o", "a", "s", "g", "k", "l", "z", "c", "n");

echo str_replace($lv_burti, $eng_burti, "mārtiņš");

 

izvada: martins

 

Faila kodējums ir UTF-8 (without BOM)?

Edited by briedis
Link to comment
Share on other sites

iconv arī negrib strādāt

function fixlink($title){
   $title = strtolower($title);
   $title = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $title);
   return $title;
}

vienkārši izvāc tos burtus, nevis nomaina.

 

un faila kodējums ir UTF-8 without BOM.

Link to comment
Share on other sites

hmmm

 

kas nav riktīgi? kā funkcija nestrādā, bet kā ne-funkcija strādā.

 

šis nestrādā

function fixlink($title){
   $title = strtolower($title);
   $lv_burti = array("ē", "ŗ", "ū", "ī", "ō", "ā", "š", "ģ", "ķ", "ļ", "ž", "č", "ņ");
   $eng_burti = array("e", "r", "u", "i", "o", "a", "s", "g", "k", "l", "z", "c", "n");
   $title = str_replace($lv_burti, $eng_burti, $title);
   return $title;
}

 

šis gan strādā

$lv_burti = array("ē", "ŗ", "ū", "ī", "ō", "ā", "š", "ģ", "ķ", "ļ", "ž", "č", "ņ");
$eng_burti = array("e", "r", "u", "i", "o", "a", "s", "g", "k", "l", "z", "c", "n");
echo str_replace($lv_burti, $eng_burti, "mārtiņš");

 

funkcija izvada:

m�rti��

 

ne-funkcija izvada:

martins

Edited by yeahz
Link to comment
Share on other sites

tagad kad strtolower ir pēc arrayiem funkcijā, tad strādā, paldies.

mb_strtolower, starpcitu.

 

Un kā ne/funkcija varianti ir vienā failā, vai dažādos? Es sliecos domāt, ka problēmas ir ar faila kodējumu...

ko mb_strtolower darīs savādāku nekā strtolower? skatījos arī php.net - izskatījās identiskas.

 

iztestēju vienā failā ar kodējumu UTF-8 without BOM.

Bet nu tagad strādā, kā gribēju.

Link to comment
Share on other sites

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...