Search code examples
phpmysqljsontwitter

JSON from twitter API contains \u2019


This is part of my JSON file I obtain through the twitter API:

"text":"Scientists discover new method for studying molecules: Queen\u2019s researchers have discovered the method for studyi... http://bit.ly/chbweE"

I am using PHP for my project.

After using the json_decode function, \u2019 is converted into ’, which basically is really annoying.

I tried using $raw_json = preg_replace("u2019","'",$raw_json), but then the json_decode function returns NULL.

Is there any other way I can convert the \u2019 into ' ?

Thanks


Edit:

This is how I am obtaining the JSON:

// create curl resource
    $ch = curl_init();

    // set url
    curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.json?q=from%3Agizmodo&rpp=10");

    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // $output contains the output string
    $raw_json = curl_exec($ch);

    // close curl resource to free up system resources
    curl_close($ch);

Solution

  • This is probably a problem with the charset you're using in your output. If you're outputing to an HTML page, try adding the following meta tag to your <head> section:

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />