php echo"%"显示不止一次

时间:2017-06-19 00:37:16

标签: php xpath output percentage

使用数据抓取进行测试。输出I'刮,是百分比。所以我基本上打了一个

echo "%<br>";

在实际数字输出的末尾

echo $ret_[66];

然而,问题是百分比实际上也出现在数字之前,这是不可取的。这是输出:

%
-0.02%

而我想要获得的只是-0.02%

显然,我在做错了PHP。我非常感谢任何反馈/解决方案。谢谢!

完整代码:

<?php

error_reporting(E_ALL^E_NOTICE^E_WARNING);

include_once "global.php";

$doc = new DOMDocument;

// We don't want to bother with white spaces
$doc->preserveWhiteSpace = false;
$doc->strictErrorChecking = false;
$doc->recover = true;
$doc->loadHTMLFile('http://www.moneycontrol.com/markets/global-indices/');

$xpath = new DOMXPath($doc);
$query = "//div[@class='MT10']";
$entries = $xpath->query($query);

foreach ($entries as $entry) {
    $result = trim($entry->textContent); 
    $ret_ = explode(' ', $result);
    //make sure every element in the array don't start or end with blank

    foreach ($ret_ as $key => $val){
        $ret_[$key] = trim($val);
    }

    //delete the empty element and the element is blank "\n" "\r" "\t"
    //I modify this line
    $ret_ = array_values(array_filter($ret_,deleteBlankInArray));

    //echo the last element
    echo $ret_[66];
    echo "%<br>";
}

1 个答案:

答案 0 :(得分:0)

<?php
echo "%<br>";



?> 

单独的PHP代码。做同样的事情。

相关问题