PHP 获取字符串包含来自数据库的 url


PHP get string contain url from 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);
}

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

在您的

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

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

我解决了这个问题实际上我想创建 .json 文件,但是当我们在 php 页面中使用数组并显示 url 等数据时.php数据会发生变化,因为它被读取为 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);