I’ve created a script which takes names from my db and for each name creates a .php file for them. However I would like to fill this file already with a (php) header since letters such as ë é and ú are not shown correctly without it.
So far i’ve got this:
<?php
// ...
while($row = mysql_fetch_array($res)){
$file = "Map/" . $row['name'] . ".php";
$fh = fopen("$file", "w+");
if($fh==false){
die("unable to create file");
}
echo "$file created <br/>";
$stringData = "<center><h1>". $row['name'] . "</h1></center>\n
No text available just yet.";
fwrite($fh, $stringData);
}
fclose($fh);
?>
What i would like to do now is place the following line of code even before the center tag:
<?php header('Content-Type: text/html; charset=ISO-8859-15'); ?>
As i retrieve the stored text from the .php file using an ajax request (with JQuery), the header must be in the file in order to be able to show those special letters. Thus my question: how can i place this line of code in each file, rather than php just executing it? (Or if this can be done easier, how so?)
Edit after comment:
After the script has run i would like to have a file that looks like this:
<?php header('Content-Type: text/html; charset=ISO-8859-15'); ?>
<center><h1>Chocolate</h1></center>
No text available yet.
Try adding this, immediately after opening the file:
PHP is smart enough to know that
?>is not an end-PHP marker when it appears in a string literal.