PHP generates a static page by remotely capturing static content

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.