Requirement: capture part of the content of a page, and then iframe to another page. When iframe is used, you do not need to access the source page every time. Instead, you only read the Source Page once a day and generate a file. When iframe is used, you only access the temporary file, that is, pseudo cache. This method is suitable for pages with low access traffic and reduces the database access pressure.
The program is designed as follows:
<? Phpfunction get_page_content () {$ url = "http://www.bkjia.com/"; $ contents = file_get_contents ($ url ); // use the following code if Chinese characters are garbled: // $ getcontent = iconv ("gb2312", "UTF-8", $ contents); // echo $ contents; // $ pos = strstr ($ contents, '<div class = "hot_news">'); // print_r ($ pos ); $ array = explode ('<div class = "hot_news">', $ contents); $ htmlarray = explode ('<div class = "car_tab border4"> ', $ array [0]); // HTML section $ cssarray = explode (' <Div class = "hometop"> ', $ htmlarray [0]); $ css_rem_inner = explode (' <! -- [If! IE]> navigation <! [Endif] --> ', $ cssarray [0]); $ css_min = explode (' <script type = "text/javascript" src = "http://www.bkjia.com/ad_comm_t.js"> ', $ css_rem_inner [0]); $ str_css = $ css_min [0]; $ head = '<base target = "_ blank"> </base>
Explanation:
$ Cache_time = 60*60*24; the cache time is one day.
If (time ()-$ cache_time> floor (@ filemtime ($ cache_file) if the current time minus one day is greater than the modification time of the temporary file.
$ Content = get_page_content (); read the page content and regenerate the temporary file.
That's simple.