PDA

View Full Version : Giới hạn số từ hiện ra ?



phattai95
04-01-2009, 05:27
Chào các bác ! Mình có một đoạn mã như sau


<?php
class get {
public function curl($method = 'GET',$vars,$url,$fl = 0,$head = 0,$nobody = 0)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
if ($method == 'POST')
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION,$fl);
curl_setopt($ch, CURLOPT_HEADER,$head);
curl_setopt($ch, CURLOPT_NOBODY,$nobody);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
ob_start();
$result = curl_exec($ch);
curl_close($ch);
ob_end_clean();
return $result;
}
}
$get = new get();
if($keyword) {
$keyword = str_replace(" ", '+', $keyword);
$m_per_page = 20;
// NHACCUATUI.COM
for ($page=1; $page<5;$page++){
$url = "http://nhaccuatui.com/tim_kiem?key=".$keyword."&page=".$page;
$htm_url = $get->curl('GET','',$url,0,0,0);
$htm_song = explode('<td style="text-align:center;">',$htm_url);
for ($i=1; $i<count($htm_song);$i++){
$song_id = explode('<p><a href="/nghe?M=', $htm_song[$i]);
$song_id = explode('"><b>', $song_id[1]);
$song_name = explode('<p><a href="/nghe?M='.$song_id[0].'"><b>', $htm_song[$i]);
$song_name = explode("</b></a></p>", $song_name[1]);
$singer_id = explode('<p class="Text01"><i>Trình bày</i>: <a href="/tim_kiem?by=casi&key=', $htm_song[$i]);
$singer_id = explode('">', $singer_id[1]);
$singer_name = explode('<p class="Text01"><i>Trình bày</i>: <a href="/tim_kiem?by=casi&key='.$singer_id[0].'">', $htm_song[$i]);
$singer_name = explode("</a></p>", $singer_name[1]);
$count_nct = count($htm_song);
$song_nct .= $song_name[0].'<br>';
}
}
echo $song_nct;

}
?>
lấy tất cả bài hát từ 5 trang của Nhaccuatui.com . Giờ em muốn phân trang nó thì làm sao ? Ý em là phân trang theo ý mình nhé ! giờ nó hiện 1 list dài nên ko biết phân trang sao giờ! em muốn mỗi trang 10 bài ! mong các bác giúp :D