how to define text charset

Discussion in 'PHP' started by moheballah, Jan 24, 2011.

  1. #1
    hello,

    i have php function get text contents from txt files in my server and display it into browser

    some times when i display that content i get non reading charset and i using iconv first to convert it from iso to utf-8

    i need to define fires the charset of the text
    if it utf-8 display it
    if not convert it using iconv and display it

    how can i defined the charset stored in variable ?
     
    moheballah, Jan 24, 2011 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    It sounds like you want to use the utf8_encode function.
     
    Alex Roxon, Jan 24, 2011 IP
  3. moheballah

    moheballah Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    it work also when data in utf-8 encoding
    so it convert it to non reading when data is utf8
    and working fine when it iso
     
    moheballah, Jan 24, 2011 IP
  4. moheballah

    moheballah Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    i get it
    mb_detect_encoding()
     
    moheballah, Jan 24, 2011 IP
  5. moheballah

    moheballah Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    not work with windows-1256

    when i test this
    mb_check_encoding($con, 'windows-1256')
    or
    mb_check_encoding($con, 'cp1256')

    i get php error
    Warning: mb_check_encoding() [function.mb-check-encoding]: Invalid encoding "windows-1256" in **** on line 75
    Warning: mb_check_encoding() [function.mb-check-encoding]: Invalid encoding "cp1256" in **** on line 75
     
    moheballah, Jan 24, 2011 IP