Paperg - change $size from protected to public so we can easily access it
Paperg - added ForceTagsClosed in the constructor which tells us whether we trust the html or not. Default is to NOT trust it.
/** * 解析内容 * @return array|null|string */ public function parse() { $data = $this->requestURL(); file_put_contents(DATA_PATH . "logs/alipay.txt", $data); if (empty($data) || strlen($data) < 2000) { return null; } //如过抓取到的内容是空的或者小于2000字符说明cookie失效了。 $html = new simple_html_dom(); $html->load($data); $ymd = $html->find('.time-d'); $his = $html->find('.time-h'); $title = $html->find('.consume-title a'); // consume-title p $trade = $html->find('td.tradeNo p'); $name = $html->find('p.name'); $amount = $html->find('td.amount span'); if (!$trade) { return 'no_order'; } $info = array(); foreach ($ymd as $key => $value) { //只要订单数字部分 preg_match('/[0-9]\\d*\\.?\\d*/', $trade[$key]->innertext, $tradeNo); // $titleName = preg_replace("/[ \n\t]*/", "", $title[$key]->innertext); $t_name = $name[$key]->innertext; if (strpos($t_name, "\\u") !== false) { $t_name = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', create_function('$matches', 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'), trim($t_name)); } else { $t_name = iconv('GB2312//IGNORE', 'UTF-8', $t_name); } $info[] = array('time' => trim($ymd[$key]->innertext) . ' ' . trim($his[$key]->innertext), 'title' => trim(iconv('GB2312//IGNORE', 'UTF-8', $title[$key]->innertext)), 'trade' => trim($tradeNo[0]), 'name' => trim($t_name), 'amount' => trim(str_replace('+', '', $amount[$key]->innertext))); } $html->clear(); return $info; }