當我從CSV導入時,它顯示出像我這樣的字符?
我的DB和表格已位於設置爲UTF-8 Unicode的CI和阿拉伯語和其他數據顯示正常,當我做選擇*
但是,當我從CSV導入和使用下面的代碼。它返回我上傳成功,但數據顯示爲?在員工姓名
請在下面找到
導入CSV從代碼...
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<style type="text/css">
body
{
margin: 0;
padding: 0;
background-color:#D6F5F5;
text-align:center;
}
.top-bar
{
width: 100%;
height: auto;
text-align: center;
background-color:#FFF;
border-bottom: 1px solid #000;
margin-bottom: 20px;
}
.inside-top-bar
{
margin-top: 5px;
margin-bottom: 5px;
}
.link
{
font-size: 18px;
text-decoration: none;
background-color: #000;
color: #FFF;
padding: 5px;
}
.link:hover
{
background-color: #9688B2;
}
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-60962033-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<div class="top-bar">
<div class="inside-top-bar">
<a href="" width="500px"></a>
<br><br>
<a href="../insert.php" class="link">← Back to main Website</a>
</div>
</div>
<h1> CSV Should be in Below Format:</h1><b>Full Name: Employee Number: Department: Email:</b>
<div style="border:1px dashed #333333; width:300px; margin:0 auto; padding:10px;">
<form name="import" method="post" enctype="multipart/form-data">
<input type="file" name="file" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
include ("connect.php");
if(isset($_POST["submit"]))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
setlocale(LC_ALL, 'ar_AE.utf8');
while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
{
$name = $filesop[0];
$emp_number = $filesop[1];
$department = $filesop[2];
$email = $filesop[3];
//$name = $filesop[0];
//$email = $filesop[1];
mysqli_query($link,"SET character_set_client=utf8");
$sql = $link->query("INSERT INTO employees (first_name, emp_number,department,email) VALUES ('$name','$emp_number','$department','$email')");
$c = $c + 1;
}
if($sql){
echo "You database has imported successfully. You have inserted ". $c ." Records";
echo '<td><a href="../view.php">← View Inserted Records</a></td>';
}else{
echo "Sorry! There is some problem.";
}
}
?>
</div>
<hr style="margin-top:300px;" />
<div align="center" style="font-size:18px;"><b><a href="">© ALL RIGHTS RESERVED BY DIBBA MUNICIPALITY FUJAIRAH</a></b></div>
</body>
</html>
我測試的數據如下 محمودعبدالعزيز
1 ABC DEF 凡阿拉伯語一個是全名/ first_name,1是員工編號,abc是department,def是電子郵件
http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – mkaatman
@mkaatman我已經讀它,親愛的...他們都設置爲UTF-8 ... –
發佈包含問題數據的CSV小樣本。 – mkaatman