title: Convert HTML entities in Json back to characters
body: <p><strong>Problem and original data</strong></p>
  <p>I have a json data which contain some HTML entities to encode some special characters (mostly from French language, like “é”, “ç”, “à”, etc.) and for html tags.
  This is a sample of my json data:</p>
  <pre><code>{
      &quot;data1&quot;: &quot;&amp;lt;p&amp;gt;Le cartulaire de 1380-1381 copi&amp;amp;eacute; au XVIIe si&amp;amp;egrave;cle et aujourd&amp;amp;rsquo;hui perdu&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt;.&quot;,
      &quot;data2&quot;: &quot;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt; Joseph CUVELIER, &amp;lt;em&amp;gt;Cartulaire de l&amp;amp;rsquo;abbaye du Val-Beno&amp;amp;icirc;t&amp;lt;/em&amp;gt;, Bruxelles, 1906, p. XI-XXVII.&amp;lt;/p&amp;gt;&quot;
  }
  </code></pre>
  <p><strong>Desired result</strong></p>
  <pre><code>{
      &quot;data1&quot;: &quot;&lt;p&gt;Le cartulaire de 1380-1381 copié au XVIIe siècle et aujourd’hui perdu&lt;strong&gt;*&lt;/strong&gt;.&quot;,
      &quot;data2&quot;: &quot;&lt;p&gt;&lt;strong&gt;*&lt;/strong&gt; Joseph CUVELIER, &lt;em&gt;Cartulaire de l’abbaye du Val-Benoît&lt;/em&gt;, Bruxelles, 1906, p. XI-XXVII.&lt;/p&gt;&quot;
  }
  </code></pre>
  <p>So, I wish to simply decode all HTML entities back to their respective characters and tags. I try to do this with php.</p>
  <p><strong>There is my current code:</strong></p>
  <pre><code>/* decode data */
  
  $jsonData = '{
          &quot;data1&quot;: &quot;&amp;lt;p&amp;gt;Le cartulaire de 1380-1381 copi&amp;amp;eacute; au XVIIe si&amp;amp;egrave;cle et aujourd&amp;amp;rsquo;hui perdu&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt;.&quot;,
          &quot;data2&quot;: &quot;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt; Joseph CUVELIER, &amp;lt;em&amp;gt;Cartulaire de l&amp;amp;rsquo;abbaye du Val-Beno&amp;amp;icirc;t&amp;lt;/em&amp;gt;, Bruxelles, 1906, p. XI-XXVII.&amp;lt;/p&amp;gt;&quot;
      }';
  $data = json_decode($jsonData, true);
  
  /* change html entities and re-encode data */
  
  $data = mb_convert_encoding($data, &quot;UTF-8&quot;, &quot;HTML-ENTITIES&quot;);
  header('Content-Type: application/json; Charset=&quot;UTF-8&quot;');
  echo json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  </code></pre>
  <p><strong>My current result:</strong></p>
  <pre><code>{
      &quot;data1&quot;: &quot;&lt;p&gt;Le cartulaire de 1380-1381 copi&amp;eacute; au XVIIe si&amp;egrave;cle et aujourd&amp;rsquo;hui perdu&lt;strong&gt;*&lt;/strong&gt;.&quot;,
      &quot;data2&quot;: &quot;&lt;p&gt;&lt;strong&gt;*&lt;/strong&gt; Joseph CUVELIER, &lt;em&gt;Cartulaire de l&amp;rsquo;abbaye du Val-Beno&amp;icirc;t&lt;/em&gt;, Bruxelles, 1906, p. XI-XXVII.&lt;/p&gt;&quot;
  }
  </code></pre>
  <p>So, HTML tags were well transformed. But the HTML entities for French special characters stay here (but instead, for example <code>&amp;amp;eacute;</code> now I have <code>&amp;eacute;</code> ).</p>
  <p><strong>Question.</strong>
  How I can convert HTML entities  back to characters?</p>
  <p><strong>You can test it online here: <a href="https://www.tehplayground.com/Z4uB5KIPPo4UQ4h1" rel="nofollow noreferrer">https://www.tehplayground.com/Z4uB5KIPPo4UQ4h1</a></strong></p>
  <p>Many thanks in advance!</p>
  <p><strong>UPDATE:</strong></p>
  <p>Finally, my data is more complex than I was imagining. In the same data some characters were preserved as “é”, “à”, “ç” etc. and some other characters was converted to HTM entities. So I can have something like this:</p>
  <pre><code>{
      &quot;someData1&quot;:
      {
          &quot;data1&quot;:
          [
              &quot;ecclésiastique&quot;
          ],
          &quot;data2&quot;: &quot;s&amp;amp;eacute;culiers&quot;
      },
      &quot;someData2&quot;:
      [
          {
              &quot;anotherData1&quot;: &quot;ecclésiastique&quot;,
              &quot;anotherData2&quot;: &quot;&amp;lt;p&amp;gt;Le cartulaire de 1380-1381 copi&amp;amp;eacute; au XVIIe si&amp;amp;egrave;cle et aujourd&amp;amp;rsquo;hui perdu&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt;.&quot;,
              &quot;anotherData3&quot;:
              {
                  &quot;text1&quot;: &quot;texte here&quot;,
                  &quot;text2&quot;: &quot;texte here&quot;
              }
          },
          {
              &quot;anotherData1&quot;: &quot;ecclésiastique&quot;,
              &quot;anotherData2&quot;: &quot;&amp;lt;p&amp;gt;Le cartulaire de 1380-1381 copi&amp;amp;eacute; au XVIIe si&amp;amp;egrave;cle et aujourd&amp;amp;rsquo;hui perdu&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt;.&quot;,
              &quot;anotherData3&quot;:
              {
                  &quot;text1&quot;: &quot;texte here&quot;,
                  &quot;text2&quot;: &quot;texte here&quot;
              }
          }
      ]
  }
  </code></pre>
  <p>So, I suppose I have to 1) Convert all data to HTML entities; 2) Convert all HTML entities back to characters…</p>
  <p>There is my current code:</p>
  <pre><code># Get data
  
  $jsonData = '{
      &quot;someData1&quot;:
      {
          &quot;data1&quot;:
          [
              &quot;ecclésiastique&quot;
          ],
          &quot;data2&quot;: &quot;s&amp;amp;eacute;culiers&quot;
      },
      &quot;someData2&quot;:
      [
          {
              &quot;anotherData1&quot;: &quot;ecclésiastique&quot;,
              &quot;anotherData2&quot;: &quot;&amp;lt;p&amp;gt;Le cartulaire de 1380-1381 copi&amp;amp;eacute; au XVIIe si&amp;amp;egrave;cle et aujourd&amp;amp;rsquo;hui perdu&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt;.&quot;,
              &quot;anotherData3&quot;:
              {
                  &quot;text1&quot;: &quot;texte here&quot;,
                  &quot;text2&quot;: &quot;texte here&quot;
              }
          },
          {
              &quot;anotherData1&quot;: &quot;ecclésiastique&quot;,
              &quot;anotherData2&quot;: &quot;&amp;lt;p&amp;gt;Le cartulaire de 1380-1381 copi&amp;amp;eacute; au XVIIe si&amp;amp;egrave;cle et aujourd&amp;amp;rsquo;hui perdu&amp;lt;strong&amp;gt;*&amp;lt;/strong&amp;gt;.&quot;,
              &quot;anotherData3&quot;:
              {
                  &quot;text1&quot;: &quot;texte here&quot;,
                  &quot;text2&quot;: &quot;texte here&quot;
              }
          }
      ]
  }';
  
  $data = json_decode($jsonData, true);
  
  # Convert character encoding
  
  $data = mb_convert_encoding($data, &quot;UTF-8&quot;, &quot;HTML-ENTITIES&quot;);
  
  # Convert HTML entities to their corresponding characters
  
  function html_decode(&amp;$item){
      $item = html_entity_decode($item);
  }
  
  array_walk_recursive($data, 'html_decode');
  
  var_dump ($data);
  </code></pre>
  <p>So, I succeed in reversing the encoding. These who was an HTML entities become special characters, and those who was a special character become HTML entities.</p>
  <p>But I don't have any idea how to get only special characters.</p>
  <p><strong>Online test: <a href="https://www.tehplayground.com/bVo3Jr5O7L9p4MXX" rel="nofollow noreferrer">https://www.tehplayground.com/bVo3Jr5O7L9p4MXX</a></strong></p>