gpt4 book ai didi

php - Json格式编码阿拉伯语

转载 作者:行者123 更新时间:2023-11-30 22:25:05 25 4
gpt4 key购买 nike

我正在使用 MySQL 数据库并使用归类 utf8_general_ci,我想从该数据库中检索一些数据,这些数据以阿拉伯语保存,但我是这样的:

{"newstitle":"??????? ????? ?? ???? ???? ???? ??? ???? ????? ???? ??? ?? ???? ?????? ???????\r\n","image":"http:\/\/new.el-ahly.com\/Admin\/Sitemanager\/ArticleFiles\/83537-ron.jpg","newstext":"????? ???? ???? ????? ???????? ?? ????? ?????? ???? ???????? ?? ???? ??????? ??? ?????? ?? ??? ???16 ?????? ???? ????? ??????? ????? ????? ????????? ????????? ??????? ???? ???? ????? ?? ????????? ???????? ??? ????? ??? ???? ?????? ??????? ???? ????? ???? ??????? ?? ?????? .\r\n \r\n??? ??????? ??? ??? ???????? ????? ??? ????? ??? ??? ??????? ?????? ?? ?????? ???? ????? ???? ???? ??????? ?????? ??? ?????? ?????? ????? ?? ????? ??? ???? ???????? ??? ??? ??? ???? ????? ??? ???? ???? ?????? ???? ?? ????","time_stamp":"about 5 minutes ago","news_url":"https:\/\/goo.gl\/U33b0h"} 

这是我的 php 脚本:

<?php
function timeago( $ptime )
{
$estimate_time = time() - $ptime;

if( $estimate_time < 1 )
{
return 'less than 1 second ago';
}

$condition = array(
12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);

foreach( $condition as $secs => $str)
{
$d = $estimate_time / $secs;

if( $d >= 1 )
{
$r = round( $d );
return 'about ' . $r . ' ' . $str . ( $r > 1 ? 's' : '' ) . ' ago';
}
}
}

$servername = "localhost";
$username = "root";
$password = "";
$db = "finaldatabase";

$conn = mysqli_connect($servername, $username, $password, $db);

if(!$conn)
{die ( "Connection failed");}

$query = "select * from playernews";

$result = mysqli_query($conn, $query);
$rows = array();

while($row = mysqli_fetch_assoc($result)) {
$News_Titles[]=$row['NewsTitle'];
$Images[]=$row['image'];
$News_Text[]=$row['NewsText'];
$Time_Stamp[]=$row['timeStamp'];
$News_Url[]=$row['url'];

//echo $row['url'];
}

// sleep for 2 sec show that the androd swipe refresh will be visible for sometime
sleep(2);

// reading offset from get parameter
$offset = isset($_GET['offset']) && $_GET['offset'] != '' ? $_GET['offset'] : 0;

// page limit
$limit = 20;
//$offset=0;


$movies_array = array();

//$rows=array_reverse($rows);

// loop through page movies
for ($j = $offset; $j < $offset + $limit && $j < sizeof($Images); $j++) {
$tmp = array();
//$tmp['rank'] = $j + 1;
$tmp['newstitle'] = $News_Titles[$j];
$tmp['image']=$Images[$j];
$tmp['newstext']=$News_Text[$j];
$time_ago =strtotime($Time_Stamp[$j]);

$tmp['time_stamp']=timeAgo($time_ago);
$tmp['news_url']=$News_Url[$j];

array_push($movies_array, $tmp);
}

//$reverse = array_reverse($movies_array, true);

// printing json response
echo json_encode($movies_array);

$curenttime="2016-02-18 22:29:13";
$time_ago =strtotime($curenttime);
//echo timeAgo($time_ago);

$myfile = fopen("movies.json", "w") or die("Unable to open file!");
$txt = json_encode($movies_array);
fwrite($myfile, $txt);
fclose($myfile);

//header("Location: movies.json"); /* Redirect browser */
exit();
?>

遇到这个问题我该怎么办?

最佳答案

$conn=mysqli_connect($servername,$username,$password,$db);
$this->mysqli->set_charset('utf8mb4'); // add this line

utf8_general_ci 也很烂,改用 utf8mb4_unicode_ci

关于php - Json格式编码阿拉伯语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35493819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com