【发布时间】:2016-09-06 21:48:26
【问题描述】:
我正在尝试将 SQL 日期时间转换为 Y/m/d G:i:s 格式。 它已经格式化,但是每个前斜杠前面都有一个额外的反斜杠...我尝试了 str_replace 和 stripslashes ,但没有一个起作用...
数据:http://www.zewde.org/instagram/script_new/data.php
代码:
<?php
define('DB_NAME', 'FollowersCount');
define('DB_USER', '******');
define('DB_PASSWORD', '******');
define('DB_HOST', '*.*.*.*');
$connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$connection) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("FollowersCount", $connection);
$sth = mysql_query("SELECT Date FROM Count ORDER BY Date");
$sthh = mysql_query("SELECT Count FROM Count ORDER BY Date");
$sthhh = mysql_query("select a.ID, a.Count,coalesce(a.Count -(select b.Count from Count b where b.ID = a.ID - 1), 5) as diff from Count a ORDER BY Date");
$rows = array();
while(($r = mysql_fetch_array($sth)) && ($rr = mysql_fetch_array($sthh)) && $rrr = mysql_fetch_array($sthhh))
{
$temp_count = intval($rr['Count']);
$temp_date1 = $r['Date'];
$myFormatForView = date("Y/m/d G:i:s", strtotime($temp_date1));
$final = str_replace("\\", "", $myFormatForView); //Doesn't work, neither does stripslashes...
$temp = array( $final, $temp_count);
$temp_s = implode(", ", $temp);
$rows['data'][][] = $temp_s;
}
$result = array();
array_push($result,$rows);
$Jz = json_encode($result, JSON_NUMERIC_CHECK);
echo $Jz;
mysql_close($connection);
?>
【问题讨论】:
-
您正在输出 JSON。
\/是您在 JSON 字符串中表达/的方式。数据中没有\,那只是编码。 -
在stackoverflow上,编辑它对你没有帮助,它仍然存在。要求模组完全删除问题并更改密码!
-
感谢您的帮助,tkausl 的答案是正确的 :)
-
另外请重新搜索
MySQLi或PDO,因为 MySQL_ 现在已弃用,一般来说不安全,甚至在 PHP7 中也不可用。请至少translate all your MySQL_ code toMySQLi_。