1.代碼如下:
- <?php
- /*
- *要實現的功能:點擊圖片進入下一頁
- */
- header("content-type:text/html;charset='utf-8'");
- $content='<p style="text-align: center">
- <span style="font-size: 16px"> </span></p>
- <p style="text-align: center">
- <span style="font-size: 16px"><img alt="Steven Meisel" src="http://hebei800.cn/uploadfile/2011/1015/20111015031909950.jpg" style="width: 596px; height: 438px" /></span></p>
- <p>
- <br />
- <span style="font-size: 14px"> <strong>這是Steven Meisel為雜志拍攝的時裝大片,色彩濃郁而不唐突,只需一眼就能緊緊抓住眼球。 ';
- $pages='<a class="a1" href="http://xxx.cn/mingxing/112.html">上一頁</a> <a href="http://xxx.cn/mingxing/112.html">1</a> <span>2</span> <a href="http://xxx.cn/mingxing/112_3.html">3</a> <a href="http://xxx.cn/mingxing/112_4.html">4</a> <a href="http://xxx.cn/mingxing/112_5.html">5</a> <a href="http://xxx.cn/mingxing/112_6.html">6</a> <a href="http://xxx.cn/mingxing/112_7.html">7</a> <a href="http://xxx.cn/mingxing/112_8.html">8</a> <a href="http://xxx.cn/mingxing/112_9.html">9</a> <a class="a1" href="http://xxx.cn/mingxing/112_3.html">下一頁</a>';
- //開源代碼Vevb.com
- $i=strrpos($pages,"href=");//最后一個href出現的位置
- $str = substr($pages,$i+5,-13);//注意:utf-8編碼下,一個漢字占用三個字節,所以 “下一頁</a>”占用13個字節
- echo $str;//結果:"http://xxx.cn/mingxing/112_3.html">
- $m=strpos($pages,$str);
- if ($m!=$i+5){//只要不是最后一張圖片,則點擊圖片進入下一頁
- $content = preg_replace('/(<img (.+)>)/Ui',"<a href=".$str."/${1}</a>",$content,-1);
- }
- echo $content;//文章內容
- ?>
2.效果圖如下:
新聞熱點
疑難解答