[英]How to use value from file_get_contents php as a number?
How to use value from file_get_contents
php as a number ? 如何使用
file_get_contents
php中的值作为数字?
I want to use $val
in this case = 50.0001
plus with 20
it's will be result 70.0001
But when i test it's show 0
why ? 我想在这种情况下使用
$val
= 50.0001
加20
,结果为70.0001
但是当我测试时显示0
为什么? how can i do ? 我能怎么做 ?
<?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;
?>
and https://www.example.com 和https://www.example.com
<span class="test">50.0001</span>
只需从节点获取textcontent即可,不要使用saveHTML。
$val = $node->item(0)->textContent;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.