如何使用json_encode在内部不加反斜杠的情况下回显值

时间:2019-02-15 22:24:49

标签: php json

当我想从带有/的json中回显数据时,它会在/处加上反斜杠。

如何删除反斜杠?

此:

$data = [
"actualdir" => "uploads/aaa"
];
echo json_encode($data);

将此作为输出:

{"actualdir":"uploads\/aaa"}

应该是:

{"actualdir":"uploads/aaa"}  

我该如何实现?

1 个答案:

答案 0 :(得分:2)

对于<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <button id="btn-decrease">A-</button> <button id="btn-orig">A</button> <button id="btn-increase">A+</button> <div id="bodytext"> <blockquote> <h1 dir="ltr" align="center"> <span style="font-size: 35pt" lang="ar-sa">title page</span></h1> <p class=MsoNormal dir=ltr style='text-align:justify'><b> <font size="5">4. some text: &quot; more text</font></b><font size="5"><span lang=ar-eg> <b>more words</b></span><b>&quot;</b></font><b><font size="5">[6].</font></b></p> <p class=MsoNormal dir=ltr style='text-align:justify'> <font size="5">new sentence..................</font> <font style="font-size: 18pt" SIZE="5"> <a style="font-size:18pt;" href="http://example.com/file.html">a link</a></font><font size="5">texttexttext.......</font><font SIZE="5" face="Times New Roman"> <span lang="AR-EG" style="font-size: 18pt; "> <a href="http://www.example.com/file.php">a link</a></span></font><font size="5">words words words words words ..</font></p> <h2 dir=ltr>&nbsp;</h2> <h2 dir=ltr><b><span style="font-size: 22pt; font-style: normal"> <a name="text">other text</a></span></b></h2> <p class=MsoNormal dir=ltr style='text-align:justify'><b> <font size="5">&quot;final words....</font></b><font size="5"><b>&quot;</b></font><b><font size="5">[7].</font></b></p> </blockquote> </div>,您可以尝试使用JSON_UNESCAPED_SLASHES选项-即:

json_encode

还有许多其他选项-请访问PHP.net

了解更多信息