我剛開始學習DOM解析器。用DOM解析器提取文本
讓我們假設在http://test.com我有4行像下面的一個,我試圖提取上下文作爲文本。 我需要的只是LPPR 051600Z 35010KT CAVOK 27/14 Q1020作爲JSON負載發送到傳入的webhook。
<FONT FACE="Monospace,Courier">LPPR 051600Z 35010KT CAVOK 27/14 Q1020</FONT><BR>
從這個例子中,我怎麼能做到這一點使用$ HTML = str_get_html和$ HTML的「找???
我設法發送完整的HTML內容,但那不是我想要的。
<?php
include_once('simple_html_dom.php');
$html = file_get_html('http://test.com')->plaintext;
// The data to send to the API
$postData = array('text' => $html);
// Setup cURL
$ch = curl_init('https://uri.com/test');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization: '.$authToken,
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
// Send the request
$response = curl_exec($ch);
// Check for errors
if($response === FALSE){
die(curl_error($ch));
}
// Decode the response
$responseData = json_decode($response, TRUE);
// Print the date from the response
echo $responseData['published'];
?>
非常感謝
這工作!謝謝! –
不客氣。請接受答案。 – iliaz