想知道是否有人知道可以使用此刮取/输出代码修改的内容,这些代码会吐出如下值:+ 40.07%,以便忽略某些值。例如,我已经在我的网站上有一个自动“+”放在每个值的前面。但是当从该源进行抓取时,它还在正值前面提供+,所以当我只需要一个+时,我得到++ 40.07类型的输出。谁知道可以添加什么来忽略输出+?我在php上非常糟糕,主要是从帮助中得到这个。非常感谢你。
// get sandpdailychange
function getSandpdailychange(){
$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://quotes.wsj.com/index/SPX');
$xpath = new DOMXPath($doc);
$query = "//span[@id='quote_change']";
$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 . "sandpdailychange",
$ret_[0]);
}
}