gpt4 book ai didi

php - Json数据库链接

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

大家好,我在处理 PHP 和 JSON 时遇到问题

这是我的 php 代码

<?php

mysql_connect("127.0.0.1","root","");
mysql_select_db("spadramatico_db");

$query = mysql_query("SELECT * FROM feed_table ORDER BY id");
$records = array();

while($obj = mysql_fetch_object($query)) {
$records [] = $obj;
}
print (json_encode($records));

?>

这是输出结果:

[{"id":"1","title":"Teste Title","image":"http:\/\/catalinaseaspa.com\/wp-content\/uploads\/2015\/03\/island-girl.jpg","desc":"Desc test","price":"1"}]

我的问题在于链接,输出如下:

http:\/\/catalinaseaspa.com\/wp-content\/uploads\/2015\/03\/island-girl.jpg

但它是这样的:

http://catalinaseaspa.com/wp-content/uploads/2015/03/island-girl.jpg

我该如何解决这个问题?谢谢:D

最佳答案

试试这个代码。将 JSON_UNESCAPED_SLASHES 添加到函数中。

<?php
mysql_connect("127.0.0.1","root","");
mysql_select_db("spadramatico_db");

$query = mysql_query("SELECT * FROM feed_table ORDER BY id");
$records = array();

while($obj = mysql_fetch_object($query)) {
$records [] = $obj;
}
print (json_encode($records,JSON_UNESCAPED_SLASHES));

?>

关于php - Json数据库链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31751050/

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