PHP get string包含来自数据库的url

时间:2014-12-03 05:54:48

标签: php database

我试图从数据库获取字符串,这是网址" http://www.google.com/"

但数据我更改为此http:\ / \ /www.google.com \ /

while($row = mysql_fetch_array($result)){
    // temporary array to create single category
    $tmp = array();
    $tmp["id"] = $row["id"];
    $tmp["name"] = $row["name"];
    $tmp["url"]= $row["url"];

    array_push($response["database"], $tmp);
}

如何在不更改的情况下获取网址。

3 个答案:

答案 0 :(得分:2)

在您的示例中,两个数据是相同的,StackOverflow是否重新格式化了您的数据?您的代码对我来说很好,也许这是数据如何插入数据库而不是如何检索的问题。您是否在phpMyAdmin或SQLyog Community Edition等SQL浏览器中查看数据以确认数据是否按预期存储?

答案 1 :(得分:1)

stripslashes()内置函数似乎可以解决问题。

答案 2 :(得分:1)

我解决了这个问题 实际上我想创建.json文件,但是当我们使用数组并在php页面.php中显示像url这样的数据时,数据将会改变,因为它被读作html代码,在json情况下我们必须创建另一个文件管理生成的文件从数据库中获取数据后

 $response = array(); $response["feed"] = array();

foreach($db->query('SELECT * FROM table') as $row) {

    $tmp = array();
    $tmp['id'] = $row['id'];
    $tmp['name'] = $row['name'];
    $tmp['url']= $row['url'];
    array_push($response['table'], $tmp);          }

//here the data posted into php page so the url change
 echo json_encode($response);
//here create .json data and write data in data.json
$fp = fopen('data.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);