|
 |
|
วิธีการดึงข่าวจาก web อื่น เป็น text file แบบอัติโนมัติทำยังไงได้บ้างคับ |
|
 |
|
|
 |
 |
|
ลองดู file_get_content() ครับ
|
 |
 |
 |
 |
Date :
2012-05-22 14:55:19 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
include('C:\AppServ\simple_html_dom.php');
$urlWithoutProtocol = "http://su.ac.th/html_news/news_template.asp?id=5622";
$request = "";
$isRequestHeader = false;
$exHeaderInfoArr = array();
$exHeaderInfoArr[] = "Content-type: text/xml";
$exHeaderInfoArr[] = "Authorization: "."Basic ".base64_encode("authen_user:authen_pwd");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlWithoutProtocol);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HEADER, (($isRequestHeader) ? 1 : 0));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if( is_array($exHeaderInfo) && !empty($exHeaderInfo) )
{
curl_setopt($ch, CURLOPT_HTTPHEADER, $exHeaderInfo);
}
$response = curl_exec($ch);
curl_close($ch);
$html = str_get_html($response);
$elem = $html->find('table td.ms09', 0)->plaintext;
$textfile= "test1.txt";
$filew= fopen($textfile, 'w');
fwrite($filew, $elem);
fclose($filew);
echo $elem;
//echo $response;
?>
</body>
</html>
คือว่า ถ้าใช้โค้ดนี้จะได้ทั้งหัวข้อและเนื้อหา แต่อยากตัดเหลือแค่เนื้อหาต้องทำยังไงคับ
|
 |
 |
 |
 |
Date :
2012-05-22 17:10:56 |
By :
Ken |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|