Outputting Form Default Input Text in UTF-8
<< Input Text Data from Web Forms
<< Building Chinese Web Sites using PHP
This section describes how to set form default input text with UTF-8 encoded characters.
From the previous section, I learned that UTF-8 byte sequences cannot be presented in &#xnnnn format in the Web page.
So I revised my test PHP script to use UTF-8 byte sequences directly to provide Web form default text:
<?php #Web-Form-Input-UTF8-Revised.php # Copyright (c) 2007 by Dr. Herong Yang, http://www.herongyang.com/ # print('<html><head>'); print('<meta http-equiv="Content-Type"'. ' content="text/html; charset=utf-8"/>'); print('</head><body>'."\n"); # Default input text $input = 'Télévision'; $input_hex = '54C3A96CC3A9766973696F6E'; # Form reply determination $reply = isset($_REQUEST["Submit"]); # Process form input data if ($reply) { if (isset($_REQUEST["Input"])) { $input = $_REQUEST["Input"]; } } # Display form print('<form>'); print('<input type="Text" size="40" maxlength="64"' . ' name="Input" value="'.$input.'"/><br/>'); print('<input type="Submit" name="Submit" value="Submit"/>'); print('</form>'."\n"); # Display reply if ($reply) { print('<pre>'."\n"); print('Content-Type:'."\n"); print(' text/html; charset=utf-8'."\n"); print('You have submitted:'."\n"); print(' Text = '.$input."\n"); print(' Text in HEX = '.strtoupper(bin2hex($input))."\n"); print(' Default HEX = '.$input_hex."\n"); print('</pre>'."\n"); } print('</body></html>'); ?>
I tested this PHP script with IE. It worked correctly both before and after click the Submit button:
Sections in This Chapter
Steps and Components Involved
Processing Web Form Input in ASCII
Processing Web Form Input in Latin1
Entering Latin1 Characters with Alt Keycodes
Testing Latin1 Alt Keycodes with IE
Processing Web Form Input in UTF-8
Testing Alt Keycodes with IE on a UTF-8 Web Page