0
我很新的PHP。我瞭解echo是如何輸出文本的,但不知道如何將其應用於下面的場景。下面,數據被刮掉並輸出。想知道是否有一種方法用file_put_contents將文本添加到輸出中,並且我試圖添加的文本是「%」。原因是下面代碼的輸出是一個每天都在變化的隨機數,而且它實際上是一個百分比,所以我希望每次都將其添加到輸出的末尾。 非常感謝您的幫助。添加文本到一個文件把內容(PHP)
// get japanchange
function getJapanchange(){
$doc = new DOMDocument;
// We don't want to bother with white spaces
$doc->preserveWhiteSpace = false;
// Most HTML Developers are chimps and produce invalid markup...
$doc->strictErrorChecking = false;
$doc->recover = true;
$doc->loadHTMLFile('http://________________//global-
indices/');
$xpath = new DOMXPath($doc);
$query = "//div[@class='MT10']";
$entries = $xpath->query($query);
foreach ($entries as $entry) {
$result = trim($entry->textContent);
$ret_ = explode(' ', $result);
//make sure every element in the array don't start or end with blank
foreach ($ret_ as $key=>$val){
$ret_[$key]=trim($val);
}
//delete the empty element and the element is blank "\n" "\r" "\t"
//I modify this line
$ret_ = array_values(array_filter($ret_,deleteBlankInArray));
//echo the last element
file_put_contents(globalVars::$_cache_dir . "japanchange",
$ret_[56]);
}
}
我不知道我完全理解的問題,所以我會處理只是其中的一部分:你使用'file_put_contents($文件名,$內容,FILE_APPEND)追加到文件; ' – Gerriet