我有一个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'的内容,以查看在某个点上它是否不是数字? – Sugar 2014-08-28 05:46:23
输出是整数..我已经用空白替换了所有的字符。 – Cael 2014-08-28 05:54:21
明白了......我只是把$ convert =(int)$ replace; – Cael 2014-08-28 06:03:59