Using PHP5 (cgi) to output template files from the filesystem and having issues spitting out raw HTML.
private function fetch($name) {
$path = $this->j->config['template_path'] . $name . '.html';
if (!file_exists($path)) {
dbgerror('Could not find the template "' . $name . '" in ' . $path);
}
$f = fopen($path, 'r');
$t = fread($f, filesize($path));
fclose($f);
if (substr($t, 0, 3) == b'\xef\xbb\xbf') {
$t = substr($t, 3);
}
return $t;
}
Even though I've added the BOM fix I'm still having problems with Firefox accepting it. You can see a live copy here: http://ircb.in/jisti/ (and the template file I threw at http://ircb.in/jisti/home.html if you want to check it out)
Any idea how to fix this? o_o
Another way to remove the BOM which is Unicode code point U+FEFF
If you are reading some API using
file_get_contents
and got an inexplicableNULL
fromjson_decode
, check the value ofjson_last_error()
: sometimes the value returned fromfile_get_contents
will have an extraneous BOM that is almost invisible when you inspect the string, but will makejson_last_error()
to returnJSON_ERROR_SYNTAX
(4).In this case, check the first 3 bytes - echoing them is not very useful because the BOM is invisible on most settings:
If the line above returns TRUE for you, then a simple test may fix the problem:
This might help. let me know if you care for me to expand my thought process.
Result: