1

我想将输入到 textarea 中的马拉雅拉姆文文本保存到 mysql。但是,当我尝试接受表单提交时的马拉雅拉姆语内容时,它会像 ാീàµ,ബഗഗജജ 字符一样返回。但是我使用了 utf-8 编码。谁能帮我。我所做的代码如下:

<?php
$dbLink = mysql_connect('localhost', 'root', 'root');
mysql_query("SET character_set_results=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF8');
mysql_select_db('test',$dblink);
mysql_query("set names 'utf8'",$dbLink);
if(isset($_POST['txt1']))
{
$txt= $_POST['txt1']; // get the unicode text from a submit action. 
$cQry= "insert into news (news) values ('$txt')" ; 
$cresult = mysql_query($cQry,$dbLink); 
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8" />
</head>
<body>
<input type="hidden" id="MicrosoftILITWebEmbedInfo" attachMode="optout" value="">
<script type="text/javascript"  src="http://ilit.microsoft.com/bookmarklet/script/Malayalam.js" defer="defer"></script>
<form action="" method="post" accept-charset="utf-8">
<textarea rows="10" charset="utf-8" cols="20" name="txt1"></textarea>
<input type="submit" value="Submit">
</form>
</body>
</html>

先感谢您。

4

3 回答 3

2
change malayalam text to unicode in backend them save to database .

use below function, onblur event to convert text to unicode:

function convertToHex(num) { 
var code ;
var  code2 ='' ;
var code3 ='';
  for (i=0;i<num.length;i++) 
    {
     code = num.charCodeAt(i).toString(16).toUpperCase();
    code3 = '';
         for(j=0; j<4-code.length; j++)
     {
       code3 += '0'; 
     }
    code2 +='%u'+ code3 +code;
     } 
     return code2; 
}
于 2013-08-06T10:05:24.913 回答
0

我为获得结果所做的代码更改是:

<?php
// Using mysql
$dbLink=mysql_connect('localhost', 'root', 'root') or die('Could not connect: ' .     mysql_error());
mysql_select_db('test') or die('Could not select database');
mysql_query("set names 'utf8'",$dbLink);
if (!empty($_POST['ta'])) {
$val= $_POST['ta'];
$val=utf8_encode($val);
$qry="insert into news(id,news)values ('','$val')";
mysql_query($qry);  
}
$result = mysql_query("SELECT * FROM news");
while ($row = mysql_fetch_row($result)) {
echo $row[1]; echo "<br>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="index.php">
<textarea name="ta" rows="6" cols="6"></textarea>   
<input type="submit" />
</form>
</body>
</html> 
于 2013-08-06T12:07:47.090 回答
0

只需将名称的排序规则设置为数据库中的 utf8-general_ci 即可。您不需要对 php 代码进行任何更改。

于 2015-09-11T05:35:25.967 回答