[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

utf8 to latin5

Posted on 2007-07-24
5
Medium Priority
?
893 Views
Last Modified: 2012-08-14
i wrote a function to convert some unenglish characters to turkish characters

function link_olsun_lan($word) {
$word = strtolower($word);
$word = str_replace("ç","c",$word);
$word = str_replace("Ç","c",$word);
$word = str_replace("ö","o",$word);
$word = str_replace("ü","u",$word);
$word = str_replace("Ü","u",$word);
$word = str_replace("","g",$word);
$word = str_replace("","g",$word);
$word = str_replace("Ö","o",$word);
$word = str_replace("1","i",$word);
$word = str_replace("0","i",$word);
$word = str_replace("_","s",$word);
$word = str_replace("^","s",$word);
return $word;
      }

but this function works if the parameter $word is in latin5 format.if the parameter $word is in utf8 format this function does not work.i think for example the character 'Ç' does not equal exactly 'Ç'.thus the function does not change the character 'Ç' with character c.what kind of way do i have to fallow to solve this problem.
0
Comment
Question by:btocakci
  • 2
  • 2
5 Comments
 

Author Comment

by:btocakci
ID: 19562672
sorry.the function is this.

function link_olsun_lan($word) {
$word = strtolower($word);
$word = str_replace("ç","c",$word);
$word = str_replace("Ç","c",$word);
$word = str_replace("ö","o",$word);
$word = str_replace("Ö","o",$word);
$word = str_replace("ü","u",$word);
$word = str_replace("Ü","u",$word);
$word = str_replace("","g",$word);
$word = str_replace("","g",$word);
$word = str_replace("0","i",$word);
$word = str_replace("I","i",$word);
$word = str_replace("^","s",$word);
$word = str_replace("_","s",$word);
return $word;
      }
0
 
LVL 48

Expert Comment

by:hernst42
ID: 19562873
If you have utf8 you need to enter these characters as utf8 and then do the str_replace. Other method is to use iconv:

setlocale(LC_CTYPE, 'tr_TR');
echo iconv('UTF-8', 'ASCII//TRANSLIT', 'your text in utf8');
0
 

Author Comment

by:btocakci
ID: 19563032
i wrote the function

function link_olsun_lan($yazicik) {
      $ara   = array ('ı','Å?','ü','ç','ö','Ä?','Åx','Ã!','Ä°','Äx','Åz','Ã','ÃS','ı','Å?','ç','ö','Ä?','Åx','Ã!','Ä°','Äx','Åz','Ã','ÃS','ü','Äx',' ','Ã');
      $degis = array ('i','s','u','c','o','g','s','C','i','g','s','o','u','i', 's', 'c', 'o', 'g', 's', 'c', 'i', 'g', 's', 'o', 'u', 'u', 'g','-','S');
      $yeni  = str_replace($ara, $degis, $yazicik);    
    return($yeni);
      }

but there is one last character that i am in problem with.that is

http://www.internethaber.com/images/word/k23.gif

any help?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 19563253
hmm, you're catched by various coding traps ...

First of all, you need to to decide in which coding your script file is (ASCII, latin5, UTF-8, ...),
second you need to know which coding your (PHP) interpreter understands,
third you need to know which coding will be deliverd by your web server,
and finally -to view the result correctly as you expect it- you browser needs to be configured for exactly the same coding *and not* be switched to quirks mode.

Said this, I recommend that you use hex values for your characters in your .php code, that would at least eleminate a couple of en-/decoding problems while the code and its results traverses several systems.

For your k23.gif I'd use 0xe7 (hex) or 231 (integer) or \u00e7 (unicode) or ç or Ş (HTML entity).
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 1500 total points
ID: 19572759
To work around coding issues in various editor I suggest you use:
 $ara   = array (chr(183).chr(195), chr(..).(chr(..),
(183 and 195 example values, not real for ı
So your entered values will not screwd up with any editor you use and the encoding on the server or transfer.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question