How to convert these characters to normal UTF8 by php

Discussion in 'PHP' started by trecords, Apr 3, 2012.

  1. #1
    Hi,

    I want to endocde these characters into normal UTF8 characters:

    This:
    Buradan saytınızda məqalə, səhifə və ya hər hansı materialəniza yazılan şərhləri idarə edə bilərsiniz
    Code (markup):
    Have to be converted to:
    Buradan saytınızda məqalə, səhifə və ya hər hansı materialıniza yazılan şərhləri idarə edə bilərsiniz
    Code (markup):
    Please let me know how to convert first to second, i have manually converted second line but you have to give me code this will translate these umlauts.

    Thanks,
     
    Solved! View solution.
    trecords, Apr 3, 2012 IP
  2. #2
    Try iconv

    Knowledge base: http://en.wikipedia.org/wiki/Iconv


    example usage:

    
    <?php
    $data = "Buradan saytınızda məqalə, səhifə və ya hər hansı materialəniza yazılan şərhləri idarə edə bilərsiniz";
    ##$convert = iconv("UTF-8", "ISO-8859-1//IGNORE", $data); umlauts render failure
    $convert = iconv("UTF-8", "UTF-8//TRANSLIT", $data); #fixed (works with //IGNORE on Xampp as well)
    echo $convert;
    //returns Buradan saytınızda məqalə, səhifə və ya hər hansı materialəniza yazılan şərhləri idarə edə bilərsiniz
    ?>
    
    PHP:
    -edit-

    fixed translate issue with 'É™'

    you might want to play around with conversion to render appropriate char (given Azerbaijani language Cyrillic and Latin mix: iso-8859-5 Windows-1251 & iso-8859-9 Windows-1254) on production server since I tested this in windows environment only.

    another method using convmap (below):
    
    $data = "Buradan saytınızda məqalə, səhifə və ya hər hansı materialəniza yazılan şərhləri idarə edə bilərsiniz";
    echo mb_encode_numericentity($data, array(0x0, 0xffff, 0, 0xffff), 'UTF-8');
    
    PHP:

    :D


    ROOFIS
     
    Last edited: Apr 4, 2012
    ROOFIS, Apr 4, 2012 IP
  3. trecords

    trecords Well-Known Member

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Hmm I will try this method, but i have also created such thing:

    $tsan = array("ğ","ç","ü","ə","ş","ö","ı","Ş","Ü","Ə","Ç","Ö","Ğ");
    $tnan = array("ğ","ç","ü","ə","ş","ö","ı","Ş","Ü","Ə","Ç","Ö","Ğ");
    
    $cont = str_replace($tsan, $tnan, $data);
    PHP:
    Sure this is not complete characters, but works OK for Azerbaijani language.
    Thanks for information :)
     
    trecords, Apr 4, 2012 IP