私は非常に新しいPHPです。エコーはテキストを出力する方法ですが、以下のシナリオでテキストを適用する方法はわかりません。以下では、データをスクラップして出力しています。 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]);
}
}
を行うことができますので、私はちょうど1の部分に対処されます:、あなたがますfile_put_contents($ファイル名、$コンテンツ、FILE_APPEND) '使用するファイルに追加します。 ' – Gerriet