排除xpath / echo(php)中的某些文本?

时间:2017-06-10 23:27:17

标签: php xpath hide

进行一些测试,并想知道在xpath / echo期间删除一些不需要的文本的最佳方法。下面的PHP代码正在吐出下面的结果

// stock trebnds
$doc = new DOMDocument;

// We don't want to bother with white spaces
$doc->preserveWhiteSpace = false;

// Most HTML Developers are chimps and produce invalid markup...
$doc->strictErrorChecking = false;
$doc->recover = true;



$doc>
 loadHTMLFile('https://www.bloomberg.com/research/sectorandindustry/
overview/sectorlanding.asp');

$xpath = new DOMXPath($doc);

$query = "//table[@id='sectorTable']";

$entries = $xpath->query($query);
foreach ($entries as $entry) {
echo trim($entry->textContent);  // use `trim` to eliminate spaces


}

更新时间:下午4:01 ETSector绩效每股收益(TTM)价格销售额(TTM)股息期1个月3个月年初至今消费者自由裁量权17行业-0.42%+ 4.71%+ 10.52%16.5x1.0x1.27%消费者订单9行业+ 2.85 %+ 3.33%+ 8.58%15.1x1.0x2.86%Energy3 Industries-2.24%-5.67%-13.57%14.0x1.2x1.74%Financials12 Industries + 2.36%-1.53​​%+ 3.77%15.2x2.1x1.91% Health Care8 Industries + 2.52%+ 2.85%+ 13.12%18.2x1.2x1.86%Industrials17 Industries + 1.01%+ 3.55%+ 7.21%15.7x1.1x1.85%Information Technology10 Industries + 1.41%+ 7.36%+ 18.03%14.8 x2.1x0.90%Materials6 Industries + 3.26%+ 4.63%+ 8.91%13.2x1.1x1.79%Telecommunications Services3 Industries + 1.08%-4.79%-8.36%22.6x1.3x4.83%Utilities6 Industries + 4.33%+ 6.29 %+ 9.34%17.1x1.3x3

任何人都知道我可以插入的一些代码,基本上会删除我想要的任何内容,因为php是“吐出来的?”例如,我想删除第一行,“更新时间:下午4:01 ETSector性能价格每股收益(TTM)价格销售额(TTM)DividendYield”

我假设在php中存在某种隐藏文本功能。

感谢您对此的任何想法!!

0 个答案:

没有答案