2017-08-16 84 views
0

如何使用file_get_contents php中的值作爲數字?如何使用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; 
?> 

https://www.example.com

<span class="test">50.0001</span> 
+0

你可以var_dump到$ node和$ val嗎? –

回答

0

剛剛得到從節點的TextContent和不使用saveHTML。

$val = $node->item(0)->textContent; 
相關問題