簡體   English   中英

在php中使用file_put_contents時如何分頁

[英]how to pagination when using file_put_contents in php

我是這個論壇的新手,我只想問你如何使用loop來分頁到網站的不同頁面。在這里,我正在使用此代碼來實現我的結果,但未能轉到網站的下一頁

$html = file_get_contents('http://www.pakwheels.com/used-cars/search/-/?page=2');

$file = 'pakwheels.txt';

file_put_contents($file , $html, FILE_APPEND);

如您所見,鏈接看起來像這樣,但是當第2頁結果存儲在文件中時如何增加頁碼。

尚未測試此代碼,但它應該為您指明正確的方向。 這將循環5次,從第1頁開始,到第5頁結束,同時為每次循環迭代創建新的文本文件。

<?php 
for ($x = 1; $x <= 5; $x++) {
    $html = file_get_contents('http://www.pakwheels.com/used-cars/search/-/?page=' . $x . '');

   $file = 'pakwheels-' . $x . '.txt';

   file_put_contents($file , $html, FILE_APPEND);
} 
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM