Question

I'm trying to insert google results to mysql utf-8 database. But when i check inserted rows some characters seems weird. For example "doctor's handbook" inserted as "doctor's handbook". I tried htmlspecialchars_decode, urldecode but not worked.

$query="doctor's handbook";
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
    . "q=".urlencode($query)."&userip=78.160.152.204&rsz=large";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
curl_close($ch);

$json = json_decode($body);
$title = mysql_real_escape_string($result->titleNoFormatting);

mysql_query("INSERT INTO files ( title ) VALUES ('$title')", $conn))

Was it helpful?

Solution

Okey i solved the problem.

html_entity_decode($title,ENT_QUOTES);

ENT_QUOTES will convert both double and single quotes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top