如何使用file_get_contents
php中的值作为数字?
我想在这种情况下使用$val
= 50.0001
加上20
,结果是70.0001
,但是当我测试它是0
时,为什么呢?我该怎么做呢?
<?php
$html = file_get_contents('https://www.example.com');
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
$finder = new DomXPath($doc);
$node = $finder->query("//*[contains(@class, 'test')]");
$val = $doc->saveHTML($node->item(0));
$result = $val + 20;
echo $result;
?>
<span class="test">50.0001</span>
发布于 2017-08-16 04:20:56
只需从节点获取文本内容,不要使用saveHTML。
$val = $node->item(0)->textContent;
https://stackoverflow.com/questions/45704841
复制