We've 700 static HTML files in folder "music". We want to put analytic code in the end of the HTML files.. like before
</body> </html>
tags.
Please anybody let me know, how its possible with PHP code?
We've 700 static HTML files in folder "music". We want to put analytic code in the end of the HTML files.. like before
</body> </html>
tags.
Please anybody let me know, how its possible with PHP code?
Too easy. Find all files, read content, modify content, save content.
<?php
// open directory
if($handle = opendir(__DIR__)) {
// search for
$search = '</body>';
// replace with (</body> gets appended later in the script)
$replace = <<< EOF
<!-- your analytics code here -->
EOF;
// loop through entries
while(false !== ($entry = readdir($handle))) {
if(is_dir($entry)) continue; // ignore entry if it's an directory
$content = file_get_contents($entry); // open file
$content = str_replace($search, $replace . '</body>', $content); // modify contents
file_put_contents($entry, $content); // save file
}
}
echo 'done';
?>