The function completed yesterday is to generate a static title to perform static page loading. In fact, the content is still remotely loaded using ajax. Today, the optimization is made to make the test content on the test page static, in this way, the search engine can capture more content, which is conducive to SEO. The implementation method is also very simple, just define the content in the template file as & lt; {content} & gt; on the basis of the original, so that when generating static pages
The function completed yesterday is to generate a static title to perform static page loading. In fact, the content is still remotely loaded using ajax. Today, the optimization is made to make the test content on the test page static, in this way, the search engine can capture more content,
Is conducive to SEO. The implementation method is also very simple, but the content in the template file is also defined as <{content}> on the basis of the original, to facilitate the generation of static pages, replace the regular expression with the content of the exam we captured from the remote page. The specific functions to implement the function change are as follows:
Function createHtml ($ dir, $ hanzi, $ I) {$ filename = $ dir. '/index.html'; touch ($ filename); if (! Is_writeable ($ filename) {die ("File:". $ filename. "cannot be written. Please check! ") ;}$ Content = file_get_contents ('. /tpl.html '); $ shijuan = file_get_contents ('URL for remotely obtaining exam content /'. $ I); $ patterns = array (); $ patterns [0] = "/<{title}> /"; $ patterns [1] = "/<{h1}>/"; $ patterns [2] = "/<{content}>/"; $ replacements = array (); $ replacements [2] = $ shijuan; $ replacements [1] = $ hanzi. "Driving school entrance test"; $ replacements [0] = $ hanzi. "Driving School simulated test"; ksort ($ patterns); // The ksort function is used to match patterns and replacements. otherwise Sequential error ksort ($ replacements); $ content = preg_replace ($ patterns, $ replacements, $ content); file_put_contents ($ filename, $ content); echo "file ". $ filename. "created successfully!
"; Echo $ hanzi." The simulated driving test is successfully created!
";}
Page effect demonstration: Hangzhou driving school test