Good day!
I think I read almost all the questions related to PHP and BOM, still I did not find a suitable answer to my problem. So here I am:
I have a PHP script (loader.php), the first time it is run it generates a configuration file (_config.php) In this script I just store some variables concerning the environement of the first call. If the _config.php file already exists I require it in loader.php
Everything works fine but the problem is that _config.php needs to be created as UTF8. The only way it worked for me, wrt this question, was with
file_put_contents(
$folder,
"\xEF\xBB\xBF".$phpCommands
);
Of course this adds the BOM and I read it when I use the require function the second time loader.php is called, generating in the end the well known extra space issue at the beginning of the page. I tried to remove it from the final output of the page using the method suggested here but it doesn't affect the result, probably because the BOM is inserted via require and not via fopen or similar.
All my PHP scripts are UTF-8 (without BOM). The generated _config.php is UTF-8 "with BOM".
To solve the problem I have two solutions but I can't figure out how to make them work:
- Create a UTF8-encoded file without BOM (streams, iconv is not an option because of old PHP)
- require_once the file removing the BOM
Can someone help me out?
Please, don't suggest me alternative strategies to generate/store the configuration. It has to be done this way.
Thanks a lot!