 |
สอบถามคะ ดึงค่าจาก DB มาโชว์ในหน้าเว็บแต่ไม่ขึ้นเป็นภาษาไทยคะ |
|
 |
|
|
 |
 |
|
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
|
 |
 |
 |
 |
Date :
2014-08-14 00:24:46 |
By :
maisurin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$con = mysqli_connect("sql3.freesqldatabase.com","sql349437","hE7%aN4%","sql349437");
$con->set_charset("utf8");
|
 |
 |
 |
 |
Date :
2014-08-14 00:40:13 |
By :
Krungsri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
<!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" />
<title>TEST</title>
<head>
<body>
<?php
function raw_json_encode($input) {
return preg_replace_callback(
'/\\\\u([0-9a-zA-Z]{4})/',
function ($matches) {
return mb_convert_encoding(pack('H*',$matches[1]),'UTF-8','UTF-16');
},
json_encode($input)
);
}
$test=array('สวัสดีครับ', 'อยู่ไหนกันครับ','ไปก่อนนะครับ','ลาก่อนครับ');
$txt=raw_json_encode($test);
echo $txt;
?>
</body>
</html>
ตัวอย่างครับ
|
 |
 |
 |
 |
Date :
2014-08-14 11:06:33 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาโค๊ดมาแปะดูครับ
|
 |
 |
 |
 |
Date :
2014-08-14 14:23:06 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$con = mysqli_connect("sql3.freesqldatabase.com","sql349437","hE7%aN4%","sql349437");
$con ->set_charset("utf8");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
$result = mysqli_query($con,"select * from student");
while($row = mysqli_fetch_assoc($result)) {
$output[] = $row; }
}
print(json_encode($output));
//mysql_close($con);
?>
|
ประวัติการแก้ไข 2014-08-14 15:45:52
 |
 |
 |
 |
Date :
2014-08-14 15:45:17 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ทราบ ว่า php version ไหนเหรอครับ
ผมก็ทำงานได้ตามปกติครับ ไม่มี error

|
 |
 |
 |
 |
Date :
2014-08-14 15:59:57 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<!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" />
<title>TEST</title>
<head>
<body>
<?php
$test=array( array('txt1'=>'สวัสดีครับ'), array('txt2'=>'อยู่ไหนกันครับ'), array('txt3'=>'ไปก่อนนะครับ'), array('txt4'=>'ลาก่อนครับ'));
$txt=raw_json_encode($test);
echo $txt;
function mat ($matches) {
return mb_convert_encoding(pack('H*',$matches[1]),'UTF-8','UTF-16');
}
function raw_json_encode($input) {
return preg_replace_callback( '/\\\\u([0-9a-zA-Z]{4})/', mat , json_encode($input) );
}
?>
</body>
</html>
ลองดูใหม่ครับ
ถ้ารู้เวอร์ชั่น php ก็ดีนะครับ ถ้าเป็น php 5.4 ขึ้นไปมันมี อีก วิธี ครับ
|
 |
 |
 |
 |
Date :
2014-08-14 20:06:25 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php
function mat ($matches) {
return mb_convert_encoding(pack('H*',$matches[1]),'UTF-8','UTF-16');
}
function raw_json_encode($input) {
return preg_replace_callback( '/\\\\u([0-9a-zA-Z]{4})/', mat , json_encode($input) );
}
$con = mysqli_connect("sql3.freesqldatabase.com","sql349437","hE7%aN4%","sql349437");
mysql_query("SET NAMES UTF8");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
$result = mysqli_query($con,"select * from student");
while($row = mysqli_fetch_assoc($result)) {
$output[] = $row; }
}
print(raw_json_encode($output));
//mysql_close($con);
?>
ลองดูนะครับ
|
 |
 |
 |
 |
Date :
2014-08-14 20:18:39 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใส่หัวใส่หาง html หรือเปล่าครับ
ลองใส่ให้มันเต็มรูปแบบครับ
คห 16 ใช้ได้ คุณก็เอา คห 18 ไปเปรียบเทียบดู
แล้วลองเอา 2 อันนั้นมาประกอบกันดูนะครับ
|
 |
 |
 |
 |
Date :
2014-08-14 20:42:18 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<!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" />
<title>TEST</title>
<head>
<body>
<?php
$con = mysqli_connect("sql3.freesqldatabase.com","sql349437","hE7%aN4%","sql349437");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
$con->query("SET NAMES UTF8");
$result = $con->query($con,"select * from student");
while($row = $result->fetch_assoc()) {
$output[] = $row;
}
print(json_encode($output));
}
?>
</body>
</html>
ลองดู โค๊ดอันนี้ครับว่าทำได้ไหม
|
 |
 |
 |
 |
Date :
2014-08-14 20:51:24 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษครับผิด ไปนิด
Code (PHP)
<!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" />
<title>TEST</title>
<head>
<body>
<?php
$con = mysqli_connect("sql3.freesqldatabase.com","sql349437","hE7%aN4%","sql349437");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
$con->query("SET NAMES UTF8");
$result = $con->query("select * from student");
while($row = $result->fetch_assoc()) {
$output[] = $row;
}
print(json_encode($output));
}
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2014-08-14 21:05:08 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<!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" />
<title>TEST</title>
<head>
<body>
<?php
function mat ($matches) {
return mb_convert_encoding(pack('H*',$matches[1]),'UTF-8','UTF-16');
}
function raw_json_encode($input) {
return preg_replace_callback( '/\\\\u([0-9a-zA-Z]{4})/', mat , json_encode($input) );
}
$con = mysqli_connect("sql3.freesqldatabase.com","sql349437","hE7%aN4%","sql349437");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
$con->query("SET NAMES UTF8");
$result = $con->query("select * from student");
while($row = $result->fetch_assoc()) {
$output[] = $row;
}
print(raw_json_encode($output));
}
?>
</body>
</html>
คาดว่าอันนี้คงไม่ผิดแล้วนะครับ
|
 |
 |
 |
 |
Date :
2014-08-14 21:19:30 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอผมก็ลองบน android แล้วนะครับ i-mobile i-style7 andrioid 4.2.2
ก็ขึ้นให้เห็นปรกติ ใช้ chrome บน android
|
 |
 |
 |
 |
Date :
2014-08-14 21:36:13 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นจาวาหรือเปล่าเครับ
|
 |
 |
 |
 |
Date :
2014-08-14 21:46:26 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แอพใช้อะไรเขียนครับ
|
 |
 |
 |
 |
Date :
2014-08-14 21:47:27 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|