UTF8 Problems

Discussion in 'PHP' started by NoamBarz, Aug 28, 2007.

  1. #1
    I'm trying to handle data passed from an HTML form with UTF8 encoding (charset). The data reaches a php page which is suppsed to update a DB table. Before inserting the data into the DB, I would like to check that the form fields were filled out correctly. One of the things I need to check is that text fields do not include special characters. The problem is that the form is filled out in hebrew. The Hebrew characters are transformed into other characters, because of the utf8 encoding, I presume and some of these characters are illegal, as far as I'm concerned.

    If I leave the text validation out, everything works fine. However, this doesn't seem like a good solution to me.

    I tried using utf8_decode(), but that doesn't help. It onoly transforms the text into question marks "?????".

    Does anyone know what could be the problem?
     
    NoamBarz, Aug 28, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1. have you set the charset type for BOTH the html page with the form on it, and the page receiving the form, by putting this in the pages' <head> section:

    
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    HTML:
    2. have you set the charset for the form:

    
    	<form action="whatever.php" method="post" accept-charset="utf-8">
    
    HTML:
    That's all I can think of for now.
     
    sea otter, Aug 28, 2007 IP
  3. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks for the reply.

    I'll be sure to set the form's charset.

    The problem with setting the <head> charset is that setting it for the HTML page is no problem, but setting it for the php is a problem because it is a page that doesn't display anything. It updates the DB and then relocates back to another page. All actions are done on the server side, so there's nothing to display.
     
    NoamBarz, Aug 29, 2007 IP
  4. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Are the database charset and all table charsets utf-8?
     
    sea otter, Aug 29, 2007 IP
  5. sabmalik

    sabmalik Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    have u tried mb_convert_encoding() ?

    i am not really sure about hebrew character set but have u looked at using a specific charset for hebrew instead of utf-8 ?

    http://en.wikipedia.org/wiki/ISO_8859-8
     
    sabmalik, Aug 29, 2007 IP