I have a function that create a file using the function fwrite. I've noticed that after the file is created, if I open the file using the online file manager of my host, I can see an extra dot inside the file. I cannot see this dot when downloading the file on my computer (linux Mint) and viewing it.
This extra dot cause an Uncaught Error: Undefined constant "". When I remove the extra dot online everything works normally. I have no idea where this extra dot come from and why I cannot see it on my computer.
You can see on the pictures the problem same file viewed online and on my computer
Here is the code that generate the file: The file is on a subdomain folder and is generated from the main domain name.
//regenerate the spam list using the updated database
$path_to_file = '/home/xxxxxxx/domains/xxxxxx.com/public_html/xxxxxxx/banned_words.php';
$myfile = fopen($path_to_file, "w") or die("Unable to open file!");
$txt1 = "<?php // The list of not allowed words\n\$not_allowed_words = [\n";
$txt3 = "];?>";
fwrite($myfile, $txt1);
// Query to fetch stories
$stmt = $pdo->prepare('SELECT * FROM banned_words ORDER BY id ASC');
$stmt->execute();
$data = $stmt->fetchAll();
foreach ($data as $row) {
$banned_word = $row["banned_word"];
$txt2 = " '".$banned_word."',\n";
fwrite($myfile, $txt2);
}
fwrite($myfile, $txt3);
Thank you to anyone with an idea!
I tried to modify the file online (remove the extra dot) and it works I tried to download the file to modify it but when opening the file on my computer the extra dot does not appear I tried to modify the function but nothing worked
EDIT: I have the same problem when generating sitemap files in xml. I tried removing the <? tag to test but the extra character still appears
Problem resolved: I simply had to delete this line and type it again : $txt3 = "];?>";
Same problem with the sitemap files generator.