title: PHP with DataTables gives an Invalid JSON response due to quotes
body: <p>I encountered a problem fetching my data from my database and display it via DataTables. I found out that most of my data has single and double quotes and other special characters. I tried every escaping functions in PHP but it didn't work. <strong>addslashes</strong> only retrieves 59 data out of 40,000 data. So far, i have this code:</p>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>$query = mysqli_query($new_conn, "SELECT * FROM bill_of_materials");
  
  $table = '';
  
  while($row = mysqli_fetch_array($query)) {
  
  
      $table.= '{
          "allotment_code":"'.$row['allotment_code'].'",
          "activity":"'.$row['activity'].'",
          "category_name":"'.addslashes($row['category_name']).'",
          "description":"'.addslashes($row['description']).'"
      },';
  }
  
  
  $table = substr($table,0, strlen($table) - 1);
  
  echo '{"data":['.$table.']}';
  
  
  **jQuery data tables:**
  
      $(function() {
  
          $('#dataTables-example').DataTable( {
              "bLengthChange": false,
              "pageLength": 50,
              "bDeferRender": true,
              "bProcessing": true,
              "sPaginationType": "full_numbers",
              "ajax": base_url('ajax/ajaxGetBOM.php'),
              "columns":[
                  {mData: "allotment_code"},
                  {mData: "activity"},
                  {mData: "category_name"},
                  {mData: "description"}
              ],
              contentType: 'application/json',
              dataType: 'json'
          });
      })
  
      function base_url(path) {
  
          var url = 'https://192.168.3.254/'+path;
          return url;
      }
  </code></pre>
  
  <p>The error is like this:
  <a href="https://i.stack.imgur.com/OJLpD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OJLpD.png" alt="enter image description here"></a></p>