converting to "utf-8"

Discussion in 'PHP' started by abou rokaya, Sep 17, 2009.

  1. #1
    hello,
    i'm searching for a php function to convert from "windows-1256" to "utf-8"

    any idea?
     
    abou rokaya, Sep 17, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $converted = iconv("windows-1256", "UTF-8", $text
    PHP:
    You'll need to have that extension installed though.
     
    premiumscripts, Sep 17, 2009 IP
  3. abou rokaya

    abou rokaya Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i've tryed this, but it doesen't work...

    i'm using xampp, and the extension iconv is installed defaultly..

    when i check phpinfo(), i got this result:

    iconv support : enabled
    iconv implementation : "libiconv"
    iconv library version : 1.11


    Directive Local Value Master Value
    iconv.input_encoding ISO-8859-1 ISO-8859-1
    iconv.internal_encoding ISO-8859-1 ISO-8859-1
    iconv.output_encoding ISO-8859-1 ISO-8859-1

    any idea?
     
    abou rokaya, Sep 18, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What doesn't work? Do you receive an error? Obviously there was a mistake in my code (forgot the ");" at the end) Are you sure your input text is in fact windows-1256 encoded? etc.
     
    premiumscripts, Sep 18, 2009 IP
  5. abou rokaya

    abou rokaya Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no i don't receive any error, but the converted text has only unreadable charachter...
    yes i'm sure that the original text is "windows-1256", i'm trying to get some inforamtion from my forum (it's vbulletin), and to post it on my front site (it's a utf-8)...
     
    Last edited: Sep 18, 2009
    abou rokaya, Sep 18, 2009 IP
  6. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can also try mb_convert_encoding (see php.net for details)
     
    premiumscripts, Sep 18, 2009 IP
  7. abou rokaya

    abou rokaya Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i've tryed it..

    but it doesen't work...

    i'm getting string from the database of a vbulletin forum (the vbulletin data base is windows-1256) and i want to convert it to utf-8

    i've tried this :

    $forumname_utf = mb_convert_encoding($forumname,"utf-8");
    PHP:
    but also, it doesen't work..

    i'm not getting any error, but the string is not converted correctly..

    ÇáÏæÑÉ ÇáËÞÇÝíÉ ÇáÔÈÇÈíÉ
    Code (markup):
     
    abou rokaya, Sep 18, 2009 IP
  8. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You need to specify the third parameter as well.

    Was vbulletin (the script) set up correctly to work with windows-1256 or was it still using utf-8?
     
    premiumscripts, Sep 18, 2009 IP
  9. abou rokaya

    abou rokaya Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    what is the third parameter ("windowd-1256")??

    i've tried this
    $forumname_utf = mb_convert_encoding($forumname,"utf-8","windows-1256");
    PHP:
    result:
    ÇáÏæÑÉ ÇáËÞÇÝíÉ ÇáÔÈÇÈíÉ
    Code (markup):
    and i've tried this
    $forumname_utf = mb_convert_encoding($forumname,"windows-1256","utf-8");
    PHP:
    but there's not result...
     
    abou rokaya, Sep 18, 2009 IP
  10. theapparatus

    theapparatus Peon

    Messages:
    2,925
    Likes Received:
    119
    Best Answers:
    0
    Trophy Points:
    0
    #10
    theapparatus, Sep 18, 2009 IP
  11. abou rokaya

    abou rokaya Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    i've tried it...

    but it cause a lot of error...

    my vbulletin is arabic
     
    abou rokaya, Sep 18, 2009 IP
  12. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #12
    Two things to insure:

    1) Are you doing database transfer? If so, try adding this mysql option before iconv after connecting to each database:

    mysql_query("SET NAMES `utf8`);

    And for the Arabic database

    mysql_query("SET NAMES `cp1256`);

    2) If you are echoing the data to the page - to actually see the result, insure that the page is in the following format:

    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    Final Arabic text.
    </body>
    </html>
    
    Code (markup):
     
    ThePHPMaster, Sep 18, 2009 IP
  13. abou rokaya

    abou rokaya Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    i'm not trying to transfer the database...

    my web site encoding is "utf-8", and i'm trying to integrate it with my forum it's Vbulletin...

    the problem is that Vbulletin use the encoding "windows-1256", so the information getted from the vbulletin is bad displayed in my site...

    i've tryied to change the database encoding but it cause a lot of error... also the database will be larger because utf-8 is using 2 byte for each charachter...

    i've tried to use the mb_convert_encoding and the iconv functions, but also it doesen't work..

    any one can help me to solve the problem???
     
    abou rokaya, Sep 20, 2009 IP
  14. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #14
    Use iframe?
     
    ThePHPMaster, Sep 20, 2009 IP