웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
신문기사 긁어오기
2003.10.20 23:33
출처는 불명확합니다.
php 고수분들이 조금 수정을 하시면
좋은 자료가 될 듯 하여 올렸습니다.
<?
function get($url){//문서가져옮
$fp = fopen($url, "r");
while(!feof($fp)){
$tmp = fgets($fp, 900);
$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.donga.com/fbin/output?f=total";
$like[] = "$date_Y$date_M$date_D";
$newspaper[] = "연합신문";
$URL[] = "http://www.yonhapnews.co.kr/services/0400000000.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);//--> url 추출
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 "<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++)
?>
* DeX™님에 의해서 게시물 이동되었습니다 (2003-10-23 22:32)
php 고수분들이 조금 수정을 하시면
좋은 자료가 될 듯 하여 올렸습니다.
<?
function get($url){//문서가져옮
$fp = fopen($url, "r");
while(!feof($fp)){
$tmp = fgets($fp, 900);
$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.donga.com/fbin/output?f=total";
$like[] = "$date_Y$date_M$date_D";
$newspaper[] = "연합신문";
$URL[] = "http://www.yonhapnews.co.kr/services/0400000000.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);//--> url 추출
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 "<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++)
?>
* DeX™님에 의해서 게시물 이동되었습니다 (2003-10-23 22:32)
댓글 28
제목 | 글쓴이 | 날짜 |
---|---|---|
로딩 100% 후 페이지 이동시키기 [1] | ▩윤미 | 2004.04.30 |
웹페이지에 테두리 두르기 [5] | ▩윤미 | 2004.04.30 |
그림파일없이 바꾸는 그라이데이션 배경색 [3] | ▩윤미 | 2004.04.30 |
접속할때마다 다른 이미지 띄우기 [8] | ▩윤미 | 2004.04.30 |
특정위치에 떠있는 레이어 (슬라이딩 애드콘) - 노프레임홈에서의 문제해결 [8] | 검미르 | 2004.05.03 |
상태창에 머문시간 보여주기 [5] | ☺심심 | 2004.05.05 |
클릭하거나, 바탕을 더블클릭하면 나타나는 작은(크기조절가능) 메뉴 | ☺심심 | 2004.05.17 |
이미지 갤러리-이미지에 설명이나 이름을 같이 달아줄수 있는.. | webzang | 2004.05.17 |
배너를 모자이크로 슬라이드한다! [13] | ☺심심 | 2004.05.17 |
동영상을 일반 버튼으로 제어 | ☺심심 | 2004.05.23 |
왔다 갔다 이미지 스크롤 [3] | 컴도미 | 2004.05.25 |
간단한 감추기/펼치기 스크립트 (태터툴즈의 more 기능) [5] | 나이시스 | 2004.05.28 |
지바 애플 아날로그 시계 소스입니다... [4] | 한성민 | 2004.06.02 |
[StylishJAVA]레이어를 이용한 슬라이드 메뉴 [5] | ∑Ztxy | 2004.06.05 |
[추천] 가로형 배너 슬라이드
[7]
![]() | ⓣinⓣin™ | 2004.06.10 |
볼륨값이 얼마나 될까? [5] | PHASE | 2004.06.16 |
[추천] 세로형 배너 슬라이드 [4] | ⓣinⓣin™ | 2004.06.24 |
둥근테이블을 홈피에 짜고싶을때../
[12]
![]() | zEn | 2004.06.28 |
레이어 특강 1 - 큰일 나는 소스 [23] | 미친개 | 2004.06.30 |
레이어 2 - 뷁뷁뷁뷁뷁봵 [7] | 미친개 | 2004.07.04 |