SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange UTF-8 problem

    Hello guys,

    I have PHP script with form. When user fills the form, script sends data to the same script. If there is error, script displays that error to the user. If there is no error, data goes into MySQL database.

    The script looks like this:

    PHP Code:
    <?

    variables
    ...

    if (
    error){
        
    $message "Please fill this field";
    }

    if (
    ok){

    $html = <<<TEXT
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    HTML code here
    TEXT;

    exit;
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    HTML with form
    Everything works fine, all HTML displays ok in UTF-8, even error message displays ok. But when form submitted and it has no errors, I see garbage instead of normal text.

    I wonder why does it happen and how can I fix it?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    can you post the source code of the output HTML?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    can you post the source code of the output HTML?
    Solved this. I forgot to insert this into PHP:

    header('Content-Type: text/html; charset=utf-8');


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •