특정 웹페이지에서 원하는 부분만 뽑아오기

/*
특정 웹페이지에서 원하는 부분만 뽑아 오고 싶다면..

By OkStart 2002-01-24
http://phptip.pro-style.org

이 소스는 http://education.altavista.co.kr/translation/ 에서 문자 번역 된 부분을 뽑아오는 프로그램 입니다.
간단하게.. 속에 있는 부분만 뽑아 오는 것이니
뽑고자 하는 웹페이지의 HTML 만 파악 잘 하신다면 응용이 가능할듯 싶습니다.
수고 하세염..
*/

// set_time_limit(0);

function Error_str($str, $color)
{
echo “

” . $str . “

“;
exit;
}

function pullpage($host, $url, $post_text)
{
if(!($fp = @fsockopen($host, 80, &$errno, &$errstr, 3)))
{
Error_str(“[소켓 에러 ( ” . $errno . ” : ” . $errstr . ” ) ] – ” . $host . “:” . $port, “red”);
}
else
{
@fputs($fp, “POST ” . $url . ” HTTP/1.0
Host: $host
User-Agent: OkStart
Accept: text/html
Content-length: ” . strlen( $post_text ) . “

” . $post_text . “
“);
while(!@feof($fp)) $output .= @fgets( $fp, 1024 );
@fclose( $fp );
return $output;
}
}

function html_form()
{
echo “


ex). i’m a boy

“;
}

function trans($text)
{
$output = “”;
$output = pullpage(“education.altavista.co.kr”, “/cgi-bin-trans/trtxt.cgi”, “dic=4&contents=” . $text);
$output = substr($output, strpos($output, ‘(242,243,251)”>’)+15 );
$output = substr($output, 0, strpos($output, ‘‘) );
return $output;
}

html_form();

if( $act == “trans” )
{
if( !empty($text) ) $text = htmlspecialchars(stripslashes($text));
echo “원본


“;
echo nl2br($text);
$output = trans($text);
echo “

번역본

“;
echo nl2br($output);
}
?>