Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to decode (\u00D8 \u00A7 \u00D) in php
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha">How to decode Unicode escape sequences like &ldquo;\u00ed&rdquo; to proper UTF-8 encoded characters?</a> </p> </blockquote> <p>I have requested a <code>URL</code> using <code>REST</code> in <code>PHP</code> and I got this result </p> <pre><code>\u00D8 \u00A7 \u00D9 \ i \u00B3 \u016E\ \u00D8 \u00A7 \u00D9 ... \u00B9 i \u016E \ \u016E Z\u0679z \u0192 ... </code></pre> <p>but when I request the URL directly from the bowser I get the result as plain readable text </p> <p>what is this encoding, and how to decode it using <code>PHP</code> to readable text ? </p> <h2>REST client code</h2> <p>I have called this function</p> <pre><code>$result = RestClient::get($url); </code></pre> <p>.</p> <pre><code>&lt;? /** * Class RestClient * Wraps HTTP calls using cURL, aimed for accessing and testing RESTful webservice. * By Diogo Souza da Silva &lt;manifesto@manifesto.blog.br&gt; */ class RestClient { private $curl ; private $url ; private $response =""; private $headers = array(); private $method="GET"; private $params=null; private $contentType = null; private $file =null; /** * Private Constructor, sets default options */ private function __construct() { $this-&gt;curl = curl_init(); curl_setopt($this-&gt;curl,CURLOPT_RETURNTRANSFER,true); curl_setopt($this-&gt;curl,CURLOPT_AUTOREFERER,true); // This make sure will follow redirects curl_setopt($this-&gt;curl,CURLOPT_FOLLOWLOCATION,false); // This too curl_setopt($this-&gt;curl,CURLOPT_HEADER,true); // THis verbose option for extracting the headers } /** * Execute the call to the webservice * @return RestClient */ public function execute() { if($this-&gt;method === "POST") { curl_setopt($this-&gt;curl,CURLOPT_POST,true); curl_setopt($this-&gt;curl,CURLOPT_POSTFIELDS,$this-&gt;params); } else if($this-&gt;method == "GET"){ curl_setopt($this-&gt;curl,CURLOPT_HTTPGET,true); $this-&gt;treatURL(); } else if($this-&gt;method === "PUT") { curl_setopt($this-&gt;curl,CURLOPT_PUT,true); $this-&gt;treatURL(); $this-&gt;file = tmpFile(); fwrite($this-&gt;file,$this-&gt;params); fseek($this-&gt;file,0); curl_setopt($this-&gt;curl,CURLOPT_INFILE,$this-&gt;file); curl_setopt($this-&gt;curl,CURLOPT_INFILESIZE,strlen($this-&gt;params)); } else { curl_setopt($this-&gt;curl,CURLOPT_CUSTOMREQUEST,$this-&gt;method); } if($this-&gt;contentType != null) { curl_setopt($this-&gt;curl,CURLOPT_HTTPHEADER,array("Content-Type: ".$this-&gt;contentType)); } curl_setopt($this-&gt;curl,CURLOPT_URL,$this-&gt;url); $r = curl_exec($this-&gt;curl); $this-&gt;treatResponse($r); // Extract the headers and response return $this ; } /** * Treats URL */ private function treatURL(){ if(is_array($this-&gt;params) &amp;&amp; count($this-&gt;params) &gt;= 1) { // Transform parameters in key/value pars in URL if(!strpos($this-&gt;url,'?')) $this-&gt;url .= '?' ; foreach($this-&gt;params as $k=&gt;$v) { $this-&gt;url .= "&amp;".urlencode($k)."=".urlencode($v); } } return $this-&gt;url; } /* * Treats the Response for extracting the Headers and Response */ private function treatResponse($r) { if($r == null or strlen($r) &lt; 1) { return; } $parts = explode("\n\r",$r); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body while(preg_match('@HTTP/1.[0-1] 100 Continue@',$parts[0]) or preg_match("@Moved@",$parts[0])) { // Continue header must be bypass for($i=1;$i&lt;count($parts);$i++) { $parts[$i - 1] = trim($parts[$i]); } unset($parts[count($parts) - 1]); } preg_match("@Content-Type: ([a-zA-Z0-9-]+/?[a-zA-Z0-9-]*)@",$parts[0],$reg);// This extract the content type $this-&gt;headers['content-type'] = $reg[1]; preg_match("@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@",$parts[0],$reg); // This extracts the response header Code and Message $this-&gt;headers['code'] = $reg[1]; $this-&gt;headers['message'] = $reg[2]; $this-&gt;response = ""; for($i=1;$i&lt;count($parts);$i++) {//This make sure that exploded response get back togheter if($i &gt; 1) { $this-&gt;response .= "\n\r"; } $this-&gt;response .= $parts[$i]; } } /* * @return array */ public function getHeaders() { return $this-&gt;headers; } /* * @return string */ public function getResponse() { return $this-&gt;response ; } /* * HTTP response code (404,401,200,etc) * @return int */ public function getResponseCode() { return (int) $this-&gt;headers['code']; } /* * HTTP response message (Not Found, Continue, etc ) * @return string */ public function getResponseMessage() { return $this-&gt;headers['message']; } /* * Content-Type (text/plain, application/xml, etc) * @return string */ public function getResponseContentType() { return $this-&gt;headers['content-type']; } /** * This sets that will not follow redirects * @return RestClient */ public function setNoFollow() { curl_setopt($this-&gt;curl,CURLOPT_AUTOREFERER,false); curl_setopt($this-&gt;curl,CURLOPT_FOLLOWLOCATION,false); return $this; } /** * This closes the connection and release resources * @return RestClient */ public function close() { curl_close($this-&gt;curl); $this-&gt;curl = null ; if($this-&gt;file !=null) { fclose($this-&gt;file); } return $this ; } /** * Sets the URL to be Called * @return RestClient */ public function setUrl($url) { $this-&gt;url = $url; return $this; } /** * Set the Content-Type of the request to be send * Format like "application/xml" or "text/plain" or other * @param string $contentType * @return RestClient */ public function setContentType($contentType) { $this-&gt;contentType = $contentType; return $this; } /** * Set the Credentials for BASIC Authentication * @param string $user * @param string $pass * @return RestClient */ public function setCredentials($user,$pass) { if($user != null) { curl_setopt($this-&gt;curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); curl_setopt($this-&gt;curl,CURLOPT_USERPWD,"{$user}:{$pass}"); } return $this; } /** * Set the Request HTTP Method * For now, only accepts GET and POST * @param string $method * @return RestClient */ public function setMethod($method) { $this-&gt;method=$method; return $this; } /** * Set Parameters to be send on the request * It can be both a key/value par array (as in array("key"=&gt;"value")) * or a string containing the body of the request, like a XML, JSON or other * Proper content-type should be set for the body if not a array * @param mixed $params * @return RestClient */ public function setParameters($params) { $this-&gt;params=$params; return $this; } /** * Creates the RESTClient * @param string $url=null [optional] * @return RestClient */ public static function createClient($url=null) { $client = new RestClient ; if($url != null) { $client-&gt;setUrl($url); } return $client; } /** * Convenience method wrapping a commom POST call * @param string $url * @param mixed params * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default * @return RestClient */ public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") { return self::call("POST",$url,$params,$user,$pwd,$contentType); } /** * Convenience method wrapping a commom PUT call * @param string $url * @param string $body * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType=null [optional] * @return RestClient */ public static function put($url,$body,$user=null,$pwd=null,$contentType=null) { return self::call("PUT",$url,$body,$user,$pwd,$contentType); } /** * Convenience method wrapping a commom GET call * @param string $url * @param array params * @param string $user=null [optional] * @param string $password=null [optional] * @return RestClient */ public static function get($url,array $params=null,$user=null,$pwd=null) { return self::call("GET",$url,$params,$user,$pwd); } /** * Convenience method wrapping a commom delete call * @param string $url * @param array params * @param string $user=null [optional] * @param string $password=null [optional] * @return RestClient */ public static function delete($url,array $params=null,$user=null,$pwd=null) { return self::call("DELETE",$url,$params,$user,$pwd); } /** * Convenience method wrapping a commom custom call * @param string $method * @param string $url * @param string $body * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType=null [optional] * @return RestClient */ public static function call($method,$url,$body,$user=null,$pwd=null,$contentType=null) { return self::createClient($url) -&gt;setParameters($body) -&gt;setMethod($method) -&gt;setCredentials($user,$pwd) -&gt;setContentType($contentType) -&gt;execute() -&gt;close(); } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload