Forum Moderators: coopster
//get the file contents
$file = file_get_contents("somehtml.html");
//use regex to replace what's in between the body tags
$file = preg_replace("/\<body\>(.*)\<\/body\>/Uis","<body>something inside body</body>", $file);
//open the file in write mode
$myFile = "somehtml.html";
$fh = fopen($myFile, 'w') or die("can't open file");
//write the new contents to the file
fwrite($fh, $file);
fclose($fh);
if that is what you wanted to do then you can do it like i explained above you just need to define an array with your files names and then loop through this array
$file = file_get_contents("somehtml.html");
$file = str_replace("<body>","<body>something you wanna add here", $file);
$myFile = "somehtml.html";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $file);
fclose($fh);
Thanks for the reply.
I'm making a noob attempt to add the loop portion. Let me know if I'm even close:
<?php
$a= 1;
$b= 10;
while ($a <= $b) {
$file = file_get_contents("$a.html");
$file = str_replace("<body>","<body>something you wanna add here", $file);
$myFile = "$a.html";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $file);
fclose($fh);
$a++;
}
?>