title: PHP encode html for json_encode
body: <p>I am getting data of a WordPress post. In WordPress data is present in HTML format as it is tinymce edit field. In this field data is like this</p>
  
  <pre><code>&lt;div class="col-sm-12 col-lg-6"&gt;
  
  Caratteristiche principali:
  &lt;ul&gt;
      &lt;li&gt;Sistema multimediale Toyota Touch� 2 with Go con display 8'' e telecamera posteriore&lt;/li&gt;
      &lt;li&gt;Sedile guidatore con supporto lombare regolabile elettricamente&lt;/li&gt;
      &lt;li&gt;Sedili anteriori riscaldabili&lt;/li&gt;
      &lt;li&gt;Toyota Safety Sense&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have made an array with this field data and with few others.
  Now I want to encode above content in a way I can get array data in JSON format using </p>
  
  <blockquote>
    <p>json_encode</p>
  </blockquote>
  
  <p>function. When json_encode runs it does not return json because of above html data. Can you please propose me a solution how I can do this correctly. Next, I need to use this JSON data in python and to save in psql. I want to keep data in psql in html formate. </p>
  
  <p>here what I am doing </p>
  
  <pre><code>&lt;?php //php 7.0.8
  
      $data_arr = Array
  (
      'post_name' =&gt; 'toyota-c-hr-1-8-ibrida-122cv-cvt-business-24-mesi',
      'caratteristiche_tecniche' =&gt; '&lt;div class="col-sm-12 col-lg-6"&gt;
  
  Caratteristiche principali:
  &lt;ul&gt;
      &lt;li&gt;Sistema multimediale Toyota Touch® 2 with Go con display 8'' e telecamera posteriore&lt;/li&gt;
      &lt;li&gt;Sedile guidatore con supporto lombare regolabile elettricamente&lt;/li&gt;
      &lt;li&gt;Sedili anteriori riscaldabili&lt;/li&gt;
      &lt;li&gt;Toyota Safety Sense
  &lt;table class="table"&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td&gt;?&lt;/td&gt;
  &lt;td&gt;Sistema Pre-Collisione&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;?&lt;/td&gt;
  &lt;td&gt;Avviso superamento corsia&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;?&lt;/td&gt;
  &lt;td&gt;Abbaglianti automatici&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;?&lt;/td&gt;
  &lt;td&gt;Riconoscimento segnaletica stradale&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;?&lt;/td&gt;
  &lt;td&gt;Sistema Pre-Collisione con rilevamento pedoni&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;?&lt;/td&gt;
  &lt;td&gt;Cruise Control adattivo&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class="col-sm-12 col-lg-6"&gt;
  &lt;div class="col-sm-12 col-lg-6"&gt;
  &lt;table class="table table-list table-striped margin_zero"&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td&gt;Marca&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;TOYOTA&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Modello&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;C-HR&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Allestimento&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;1.8H (122CV) E-CVT Business&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Cilindrata Effettiva&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;1798 Cm3&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Cilindrata&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;1798 L&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Pacchetto (Tipo Eletta, Sport)&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;1.8H (122CV) E-CVT Business&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Model Year&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;2017&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Peso&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;1455 Kg&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Portata&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;405 Kg&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Tipo Veicolo&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;Manufacturer Vehicle&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Emissioni C02&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;86 G/Km&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Trazione&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;Front&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;div class="col-sm-12 col-lg-6"&gt;
  &lt;table class="table table-list table-striped margin_zero"&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td&gt;Consumo Combinato&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;3.8 Litri Per 100km&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Porte&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;5-Door&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Posti&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;5&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Alimentazione&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;Unleaded - Electric / &lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Cambio&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;AUT&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Potenza Massima KW&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;90 KW&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Potenza Massima CV&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;122 CV&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Cavalli Fiscali&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;19&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Corpo Veicolo&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;Sport Utility Vehicle&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Codice Ruote Anteriori&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;215/60 C17 96H&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Codice Ruote Posteriori&lt;/td&gt;
  &lt;td&gt;&lt;strong class="ng-binding"&gt;215/60 C17 96H&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/div&gt;',
      'marca' =&gt; 'Toyota'
  );
  
    echo json_encode($data_arr);
  ?&gt;
  </code></pre>
  
  <p>To me it seam like problem is with econding of sepecial charcters inside of html.</p>