and &, so we do it with str_replace(). $json = str_replace(['<', '>', '&'], ['\u003c', '\u003e', '\u0026'], $json); return file_put_contents($filename, $json); } }