각 신문사의 오늘 날짜 기사 긁어 오는 소스입니다.
<?
function get($url){
$fp = fopen($url, "r");
while(!feof($fp)){
$tmp = fgets($fp, 1024);
$temp .= $tmp;
}
fclose($fp);
return $temp;
}//function get
function Strip($all){
$link_pm=strpos($all,">");
$link=substr($all,0,$link_pm);
if(!$link) return;
if(ereg(""",$link)){
$link_p=strpos($link,""");
$link=substr($link,$link_p+1);
$link_p=strpos($link,""");
$link=substr($link,0,$link_p);
}
if(ereg("'",$link)){
$link_p=strpos($link,"'");
$link=substr($link,$link_p+1);
$link_p=strpos($link,"'");
$link=substr($link,0,$link_p);
}
$link=trim($link);
$substr=substr($all,$link_pm+1);
$substr_p=strpos($substr,"</a>");
$substr=substr($substr,0,$substr_p);
$strip=strip_tags($substr);
$strip=trim($strip);
return array(link => $link, sub => $strip);
}//function strip($all)
function makeUrl($Url, $Link){
if(!strpos($Link,"http://") && substr_count
("$Link","http://")) return $Link;
$eURL = pathinfo("$Url");
$host = parse_url($Url);
$host = $host[scheme]."://".$host[host];
$Link = "/".$Link;
if(substr_count("$Link","../")){
$Link = str_replace("./../", "", $Link);
$Link = str_replace("../", "", $Link);
$pos = strrpos($eURL["dirname"], "/");
$makeUrl = substr($eURL["dirname"],0,$pos);
$makeUrl = "$makeUrl"."$Link";
}else if(substr_count("$Link","//") && !strpos($Link, "//"))
{ //·çÆ®·Î °¡¶ó
$makeUrl = $host."/".str_replace("//", "", $Link);
}else{ //Á¦ÀÚ¸®
$Link = str_replace("./", "", $Link);
$makeUrl = $eURL["dirname"]."$Link";
}
return $makeUrl;
}
////////////////////////////////////// 날짜 설정
$date_Y = date("Y");
$date_M = date("m");
$date_D = date("d");
$mdate = "$date_Y.$date_M.$date_D";
////////////////////////////////////////////////////////////<== 신문사
별 설정
$newspaper<> = "한겨레";
$URL<> = "http://www.hani.co.kr/TOTAL/home01.html"; //한겨레 전체기사
페이지
$like<> = "$date_Y$date_M$date_D";
$newspaper<> = "조선";
$URL<> = "http://www.chosun.com/w21data/html/list/BAL.html"; //조선일
보 전체기사 페이지
$like<> = "$date_Y$date_M$date_D";
$newspaper<> = "중앙";
$URL<> = "http://www.joins.com/list/home_list.html"; //중앙일보 전
체기사 페이지
$like<> = "$date_Y$date_M$date_D";
$newspaper<> = "연합";
$URL<> = "http://www.yonhapnews.net/services/0300000000.html"; //연합
뉴스 전체기사 페이지
$like<> = "$date_Y$date_M$date_D";
////////////////////////////////////////////////////////////<== 출력 부
분
for($x=0; $x < sizeof($newspaper); $x++){
$temp = get($URL[$x]);
$all = split("href =|HREF =|href=|HREF=",$temp);
for($i=0; $i < sizeof($all); $i++){
$kisa = Strip($all[$i]);
if(ereg($like[$x], $kisa[link]) && 20 < strlen($kisa
[sub])){
$LinkURL = makeUrl($URL[$x], $kisa[link]);
echo "<br><a href='$LinkURL'>[$newspaper[$x]]
$kisa[sub]</a><br>";
}//if(ereg($like[$x], $kisa[link]) && 20 < strlen($kisa
[sub]))
}//for($i=0; $i < sizeof($all); $i++)
}//for($x=0; $x < sizeof($newspaper); $x++)
?>
미리보기 : http://0172.kr.kg/ 확장하기에는 별 무리 없는 것 같습니다.
신문사별 설정만 조금 변경 해 주시면 여러모로 쓸모가 많을 것 같습니다.