title: Decoding json (containig encoded like \u003c HTML entities) with json_decode, unexpected result
body: <p>Trying to decode this json:</p>
  
  <pre><code>$json = '{"d":{"results":[{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=\u0027web+spell+relatedsearch\u0027&amp;Query=\u0027\"\u003e\u003c/a\u003e\u003cimg src=\"&amp;$skip=0&amp;$top=1#\"\u003e\u003cscript\u003ealert(\u00273\u0027);\u003c/script\u003e\"\u0027&amp;Market=\u0027it-IT\u0027&amp;Adult=\u0027Strict\u0027&amp;Options=\u0027DisableLocationDetection+EnableHighlighting\u0027&amp;WebSearchOptions=\u0027DisableQueryAlterations\u0027","type":"ExpandableSearchResult"},"ID":"5afc1ab9-f4a7-43e1-9d14-dbec42f83c0c","WebTotal":"4","WebOffset":"0","ImageTotal":"","ImageOffset":"","VideoTotal":"","VideoOffset":"","NewsTotal":"","NewsOffset":"","SpellingSuggestionsTotal":"","AlteredQuery":"","AlterationOverrideQuery":"","Web":[{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=0&amp;$top=1","type":"WebResult"},"ID":"38cc61c8-4ce2-4013-92ee-a2fa4de3abcc","Title":"apache 2.2.21 exploits - Page 2 - Code Exploits Collection","Description":"... script\u003e password_verify \"\u003e\u003cscript\u003ealert(2);\u003c/script\u003e firstname \"\u003e\u003cscript\u003ealert(3);\u003c/script ... 703F67657470776E65643D: Administrators\u003c/a\u003e\u003cimg src=\"http://192.168.0.15/learn ...","DisplayUrl":"exploitsdownload.com/search/apache%202.2.21/2","Url":"http://exploitsdownload.com/search/apache%202.2.21/2"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=1&amp;$top=1","type":"WebResult"},"ID":"df1b6d37-efc1-4d3c-bed5-7d6e34a3d686","Title":"siteniz için htlm kodları - Sayfa 3 - Baktabul Forum","Description":"... gelecek ve sooon\") \u003c/script\u003e \u003cscript\u003e alert(\"4!!\") \u003c/script\u003e \u003cscript\u003e alert(\"3!!!\") \u003c/script\u003e \u003cscript\u003e ... BURAYA YAZIN!!!\u0027,500,300); return false\" \u003e \u003e\u003e\u003eGİRİŞ \u003c\u003c\u003c\u003c\u003c/a\u003e \u003cIMG SRC= \"http ...","DisplayUrl":"www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html","Url":"http://www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=2&amp;$top=1","type":"WebResult"},"ID":"fab98f52-bbe6-40f7-805d-5ab14b503827","Title":"php 5.2.17 exploits - Page 1 - Code Exploits Collection","Description":"... trace_results.php?product_id=117&amp;amp;project_id=40&amp;amp;funder=31\"\u003e\u003cscript\u003ealert(3);\u003c/script ... 703F67657470776E65643D: Administrators\u003c/a\u003e\u003cimg src=\"http://192.168.0.15/learn ...","DisplayUrl":"exploitsdownload.com/search/php%205.2.17","Url":"http://exploitsdownload.com/search/php%205.2.17/"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=3&amp;$top=1","type":"WebResult"},"ID":"82b3c849-4cdc-409a-95a8-a74310b723aa","Title":"DEV ARŞİV \u0027\u0027Hazır kodlar\u0027ın %90 burada\u0027\u0027 İçeri buyrun\u003e\u003e\u003e","Description":"... ve sooon\")\u003c/script\u003e \u003cscript\u003ealert(\"4!!\")\u003c/script\u003e \u003cscript\u003ealert(\"3!!!\")\u003c/script ... BURAYA YAZIN!!!\u0027,500,300); return false\"\u003e\u003e\u003e\u003eGİRİŞ\u003c\u003c\u003c\u003c\u003c/a\u003e\u003cIMG SRC=\"http ...","DisplayUrl":"www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231...","Url":"http://www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231eri-buyrungtgtgt-t180384.html"}],"Image":[],"Video":[],"News":[],"RelatedSearch":[],"SpellingSuggestions":[]}]}}';
  </code></pre>
  
  <p>php returned to me using <code>var_dump(json_decode($jsonOriginalResults, true));</code></p>
  
  <p>a wrong array with \u003c characters decoded, but why?</p>
  
  <p>I just expect a result like this:</p>
  
  <pre><code>array(1) {
    ["d"]=&gt;
    array(1) {
      ["results"]=&gt;
      array(1) {
        [0]=&gt;
        array(19) {
          ["__metadata"]=&gt;
          array(2) {
            ["uri"]=&gt;
            string(403) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=\u0027web+spell+relatedsearch\u0027&amp;Query=\u0027"\u003e\u003c/a\u003e\u003cimg src="&amp;=0&amp;=1#"\u003e\u003cscript\u003ealert(\u00273\u0027);\u003c/script\u003e"\u0027&amp;Market=\u0027it-IT\u0027&amp;Adult=\u0027Strict\u0027&amp;Options=\u0027DisableLocationDetection+EnableHighlighting\u0027&amp;WebSearchOptions=\u0027DisableQueryAlterations\u0027"
            ["type"]=&gt;
            string(22) "ExpandableSearchResult"
          }
          ["ID"]=&gt;
          string(36) "5afc1ab9-f4a7-43e1-9d14-dbec42f83c0c"
          ["WebTotal"]=&gt;
          string(1) "4"
          ["WebOffset"]=&gt;
          string(1) "0"
          ["ImageTotal"]=&gt;
          string(0) ""
          ["ImageOffset"]=&gt;
          string(0) ""
          ["VideoTotal"]=&gt;
          string(0) ""
          ["VideoOffset"]=&gt;
          string(0) ""
          ["NewsTotal"]=&gt;
          string(0) ""
          ["NewsOffset"]=&gt;
          string(0) ""
          ["SpellingSuggestionsTotal"]=&gt;
          string(0) ""
          ["AlteredQuery"]=&gt;
          string(0) ""
          ["AlterationOverrideQuery"]=&gt;
          string(0) ""
          ["Web"]=&gt;
          array(4) {
            [0]=&gt;
            array(6) {
              ["__metadata"]=&gt;
              array(2) {
                ["uri"]=&gt;
                string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=0&amp;=1"
                ["type"]=&gt;
                string(9) "WebResult"
              }
              ["ID"]=&gt;
              string(36) "38cc61c8-4ce2-4013-92ee-a2fa4de3abcc"
              ["Title"]=&gt;
              string(58) "apache 2.2.21 exploits - Page 2 - Code Exploits Collection"
              ["Description"]=&gt;
              string(257) "... script\u003e password_verify "\u003e\u003cscript\u003ealert(2);\u003c/script\u003e firstname "\u003e\u003cî€€script\u003ealert(3);\u003c/scriptî€ ... 703F67657470776E65643D: Administrators\u003c/î€€a\u003e\u003cimg srcî€="http://192.168.0.15/learn ..."
              ["DisplayUrl"]=&gt;
              string(45) "exploitsdownload.com/search/apache%202.2.21/2"
              ["Url"]=&gt;
              string(52) "http://exploitsdownload.com/search/apache%202.2.21/2"
            }
            [1]=&gt;
            array(6) {
              ["__metadata"]=&gt;
              array(2) {
                ["uri"]=&gt;
                string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=1&amp;=1"
                ["type"]=&gt;
                string(9) "WebResult"
              }
              ["ID"]=&gt;
              string(36) "df1b6d37-efc1-4d3c-bed5-7d6e34a3d686"
              ["Title"]=&gt;
              string(54) "siteniz iÃ§in htlm kodlarÄ± - Sayfa 3 - Baktabul Forum"
              ["Description"]=&gt;
              string(326) "... gelecek ve sooon") \u003c/script\u003e \u003cscript\u003e alert("4!!") \u003c/script\u003e \u003cî€€script\u003e alert("3!!!") \u003c/scriptî€\u003e \u003cscript\u003e ... BURAYA YAZIN!!!\u0027,500,300); return false" \u003e \u003e\u003e\u003eGÄ°RÄ°Åž \u003c\u003c\u003c\u003c\u003c/î€€a\u003e \u003cIMG SRCî€= "http ..."
              ["DisplayUrl"]=&gt;
              string(65) "www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html"
              ["Url"]=&gt;
              string(72) "http://www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html"
            }
            [2]=&gt;
            array(6) {
              ["__metadata"]=&gt;
              array(2) {
                ["uri"]=&gt;
                string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=2&amp;=1"
                ["type"]=&gt;
                string(9) "WebResult"
              }
              ["ID"]=&gt;
              string(36) "fab98f52-bbe6-40f7-805d-5ab14b503827"
              ["Title"]=&gt;
              string(55) "php 5.2.17 exploits - Page 1 - Code Exploits Collection"
              ["Description"]=&gt;
              string(228) "... trace_results.php?product_id=117&amp;amp;project_id=40&amp;amp;funder=31"\u003e\u003cî€€script\u003ealert(3);\u003c/scriptî€ ... 703F67657470776E65643D: Administrators\u003c/î€€a\u003e\u003cimg srcî€="http://192.168.0.15/learn ..."
              ["DisplayUrl"]=&gt;
              string(40) "exploitsdownload.com/search/php%205.2.17"
              ["Url"]=&gt;
              string(48) "http://exploitsdownload.com/search/php%205.2.17/"
            }
            [3]=&gt;
            array(6) {
              ["__metadata"]=&gt;
              array(2) {
                ["uri"]=&gt;
                string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=3&amp;=1"
                ["type"]=&gt;
                string(9) "WebResult"
              }
              ["ID"]=&gt;
              string(36) "82b3c849-4cdc-409a-95a8-a74310b723aa"
              ["Title"]=&gt;
              string(102) "DEV ARÅžÄ°V \u0027\u0027HazÄ±r kodlar\u0027Ä±n %90 burada\u0027\u0027 Ä°Ã§eri buyrun\u003e\u003e\u003e"
              ["Description"]=&gt;
              string(283) "... ve sooon")\u003c/script\u003e \u003cscript\u003ealert("4!!")\u003c/script\u003e \u003cî€€script\u003ealert("3!!!")\u003c/scriptî€ ... BURAYA YAZIN!!!\u0027,500,300); return false"\u003e\u003e\u003e\u003eGÄ°RÄ°Åž\u003c\u003c\u003c\u003c\u003c/î€€a\u003e\u003cIMG SRCî€="http ..."
              ["DisplayUrl"]=&gt;
              string(67) "www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231..."
              ["Url"]=&gt;
              string(100) "http://www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231eri-buyrungtgtgt-t180384.html"
            }
          }
          ["Image"]=&gt;
          array(0) {
          }
          ["Video"]=&gt;
          array(0) {
          }
          ["News"]=&gt;
          array(0) {
          }
          ["RelatedSearch"]=&gt;
          array(0) {
          }
          ["SpellingSuggestions"]=&gt;
          array(0) {
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>This result is obtained with this custom function:</p>
  
  <pre><code>function json_decoder($json) {
      $comment = false;
      $out = '$x=';
  
      for ($i = 0; $i &lt; strlen($json); $i++) {
          if (!$comment) {
              if (($json[$i] == '{') || ($json[$i] == '['))
                  $out .= ' array(';
              else if (($json[$i] == '}') || ($json[$i] == ']'))
                  $out .= ')';
              else if ($json[$i] == ':')
                  $out .= '=&gt;';
              else
                  $out .= $json[$i];
          } else
              $out .= $json[$i];
          if ($json[$i] == '"' &amp;&amp; $json[($i - 1)] != "\\")
              $comment = !$comment;
      }
  
      eval($out . ';');
      return $x;
  }
  </code></pre>
  
  <p>But I want to use php json_decode function not a custom one.... Any suggestion?</p>