【发布时间】:2014-08-28 05:38:08
【问题描述】:
我有一个 PHP 代码可以从网站检索值。我得到了输出,但也得到了通知: 注意:在第 19 行遇到了格式不正确的数值。
这是我的 PHP 代码:
<?php
header('Content-Type: text/html; charset=utf-8');
$grep = new DoMDocument();
@$grep->loadHTMLFile("https://www.postme.com.my/men-1.html");
$finder = new DomXPath($grep);
$class = "amount";
$nodes = $finder->query("//*[contains(@class, '$class')]");
$i = 0;
foreach ($nodes as $node) {
if ($i<1) {
$span = $node->childNodes;
$replace = str_replace("Items 1-12 of", "",$span->item(0)->nodeValue);
echo number_format($replace, 0 , '.' , ',' ) . '<br/>';
}
$i++;
}
?>
如何更正它,以便在我为其分配数字格式时不会出现通知。 谢谢!
【问题讨论】:
-
你有没有在每次迭代时检查
$replace的内容,看看它是否在某个时候不是一个数字? -
输出是整数..我已经用空白替换了所有字符。
-
知道了...我只是把 $convert = (int)$replace;