html 원하는 데이타 추출
html 에서 테이타 뽑기
<?
$file =file("
http://www.kns.tv/news/articleView.html?idxno=53099");
foreach($file as $key=>$value)
{
$a .=$value;
}
$a1="<td class=\"view_t\">";
$z="<\/td>";
$z=ins_tmp_work($a,$a1,$z);
echo "제목: $z <br>";
$c1="<td class=\"view_sub_t\">";
$z="<\/td>";
$x=ins_tmp_work($a,$c1,$z);
echo "부제목 : $x <br>";
$y=ins_tmp_work($a,"<td bgcolor=\"EFEFEF\">","<\/font>");
$y=strip_tags($y);
echo"날짜: $y <br>";
$y=ins_tmp_work($a,"<td align=\"right\" bgcolor=\"EFEFEF\">","<\/font>");
$y=strip_tags($y);
echo"기자: $y <br>";
//print_r($x);
$y=ins_tmp_work($a,"<td class=\"view_r\" id=\"articleBody\">","<!--추천위젯시작\/\/-->");
echo"본문: $y <br>";
//////////////////////////////////////////////////////////////////////////////////////
function ins_tmp_work($contents,$a,$b) {
$regs = preg_split("/($a|$b)/",$contents, -1, PREG_SPLIT_DELIM_CAPTURE);
$key=key($regs);
$regs[$key] = trim($regs[$key]);
$tmp_count=sizeof($regs);
//echo"pp $tmp_count pp";
for($i=0 ; $i < $tmp_count ; $i++) {
if($regs[$i] =="$a") {
$tmp_t=$i-1;
$tmp_arr_up_conent=$regs[$tmp_t];
unset($tmp_t);
$tmp_t=$i+1;
$tmp_arr_loop=$regs[$tmp_t];
} else if($regs[$i] =="$b") {
unset($tmp_t);
$tmp_t=$i+1;
$tmp_arr_down_conent=$regs[$tmp_t];
}
}
return $tmp_arr_loop;
}
///////////////////////////////////////////////////////////////////////////////
?>