Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Unicode string from HTML form to PHP script

Status
Not open for further replies.

sen5241b

IS-IT--Management
Sep 27, 2007
199
US
Without the meta statement identifying the page as 'charset =UTF-8' (Unicode), the HTML form doesn't pass the Unicode text correctly to the PHP script. I've tried with and without the 'charset=UTF-8' statement.

I have other users who may call my script from HTML forms, their own PHP script or some other language and so I cannot always rely on the HTML form to identify the charset as UTF-8 using a meta statement. (I've found that meta statements in general can be missing or unreliable).

Anyone have an example of how to decode the Unicode string to decimal or hex data so it can be passed from the HTML from to my PHP script?


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> ';
<html> 
<head> 
<meta http-equiv="content-type" content="text/html;charset=utf-8"> 
<title>Enter Unicode Test String</title>
<style type="text/css">
h1 {font-size: 800%}
h2 {text-align: center; color: red; font-size: 300%}
h3 {font-size: 200%}
h4 {text-align: center; font-size: 120%}
h5 {text-align: center; font-size: 120%}
p {font-size: 100%}
h3 {font-family: times}
h2.pos_left
{

}
h2.pos_right
{
position:relative;
left:20px
}

div.figureleft {
  float: left;
  width: 25%;
  border: thin red solid;
  padding: 0.5em;  }
IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto }
  #clearbreak {
	clear: both; }
	</style>
</head> 

<body bgcolor="#33CCCC" lang=EN-US link=red vlink=purple style='tab-interval:
.5in'>
<H2> The Page</H2>
<H4> Enter unicode text</H4>
<H4>
<form action="word14.php" method="post">
<span style="position: relative; LEFT: -20.5px">   &nbsp; 
<textarea name="changestr" id="changestr" rows="1" cols="100"tabindex="1" value="" </textarea> 
<BR><BR>
<input type="submit" VALUE="Test" />
 </span>
 </form>
</H4>
</body>
</html>

Code:
<?PHP
echo 'well? changestr=';
var_dump($_POST['changestr']);
$changestr = $_POST['changestr'];
// Fold Latin-1 Supplement unicode block
echo '<br>before all   $changestr=';
var_dump($changestr); 
$encode = mb_detect_encoding($changestr, "auto");
echo ' <br> $encode=' . $encode;
$search  = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
$replace = array('A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'x', 'O', 'U', 'U', 'U', 'U', 'Y', 'b', 'B', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'b', 'y');
$changestr1 = str_replace($search, $replace, $changestr);
$changestr = $changestr1; 
echo '<br>after 1st fold   $changestr1=';
var_dump($changestr1); 
echo '<br>'; 
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top