The common part of the page loads the generated JS into the desired location in JavaScript document.write () Footer.js put into the body bottom introduced ... <script src= "Js/footer.js" ></ Script></body>--------------------------------------Php.exe Add the folder to the PATH environment variable, enter PHP at the command line Footer.html--------------------------------------
<?php$handle = fopen ("footer.html", "R"); Enter the HTML file $dest = fopen ("Footer.js", "w"); Output JS file if ($handle) {fwrite ($dest, "(function () {\ n"); while ($buffer = Fgets ($handle, 4096))!== false) { $s = addslashes ($buffer); $line = "\tdocument.write (\"). RTrim ($s , "\ r \ n"). "\"); \ n "; fwrite ($dest, $line); } Fwrite ($dest, "}). Call ();"); if (!feof ($handle)) { echo "error:unexpected fgets () fail\n"; } Fclose ($handle); Fclose ($dest);}? >
Input file:
<div id= "Footer" ><div class= "container text-center" ><div class= "copyright" >copyright?2017~2020 <a href= "http://www.tsinghuadtv.com/" target= "_blank" > Ling Software </a> Technical Support <a href= "/http/ www.miitbeian.gov.cn "target=" _blank "> Beijing ICP No. 13,010,031th </a></div></div></div>
Output file:
(function () {document.write ("<div id=\" Footer\ ">");d ocument.write ("<div class=\" Container text-center\ " > ");d ocument.write (" <div class=\ "copyright\" >copyright?2017~2020 ");d ocument.write (" <a href=\ "/http/ Www.tsinghuadtv.com/\ "target=\" _blank\ "> Ling Software </a> Technical Support");d ocument.write ("<a href=\"/http/ Www.miitbeian.gov.cn\ "target=\" _blank\ "> Beijing ICP No. 13,010,031th </a>");d ocument.write ("</div>"); document.write ("</div>");d ocument.write ("</div>");}). Call ();
The public part of the PHP page is converted to JS document.write (); And is wrapped by an anonymous function