douxiong0668 2016-09-06 21:48 采纳率: 100%
浏览 169

从日期中删除反斜杠()[关闭]

I'm trying to convert SQL datetime to a Y/m/d G:i:s format. It has formated, but there is an extra backslash in front of every frontslash... I've tried str_replace and stripslashes and non of them have worked...

Data: http://www.zewde.org/instagram/script_new/data.php

Code:

<?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);
?>
  • 写回答

2条回答 默认 最新

  • douzepao0281 2016-09-06 21:52
    关注

    This is json_encodes fault.

    json_encode() options:

    JSON_UNESCAPED_SLASHES
    Don't escape /. Available since PHP 5.4.0.

    So

    $Jz = json_encode($result, JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES );
    

    should get rid of those backslashes.

    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行