1

I'm trying to get string from database which is url "http://www.google.com/"

but data I get changed to this 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);
}

how can I get the url without changed.

2

3 Answers 3

2

In your example the two pieces of data are identical, did StackOverflow reformat your data? Your code looks fine to me, perhaps it is a problem with how the data is inserted into the database rather than how it is retrieved. Have you looked at the data in an SQL browser like phpMyAdmin or SQLyog Community Edition to confirm the data is stored as you expect?

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is still there, I try to use both PDO and MySQLi not work.. actually I'm working in json and I put this array in json_encode(), do you think this problem is caused by array?
1

the stripslashes() builtin function would seem to do the trick.

Comments

1

I solve this problem actually I want to create .json file, but when we use array and show data like url in php page .php the data will change because it's read as an html code, in json case we have to create another file with in file managment generated after getting data from database

 $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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.