使用 echo str 隐藏特定文本 (php)?

hiding specific text (php) using echo str?

使用我的 PHP 代码时遇到问题。 (我真的很不擅长 php fyi)

echo str_replace("DJIA", "", "REGISTER DJIA here");

上面应该排除任何说 DJIA 的文字,它应该隐藏它。

然而,当在下面的代码中使用时,它会抓取 DJIA 股票信息并重新显示它,它并没有摆脱 "DJIA." 有什么想法吗?

<?php 

$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('http://www.nbcnews.com/business');

$xpath = new DOMXPath($doc);

$query = "//div[@class='market']";

$entries = $xpath->query($query);

foreach ($entries as $entry) {
echo trim($entry->textContent);  // use `trim` to eliminate spaces
echo str_replace("DJIA", "", "REGISTER DJIA here");
}

试试这个:

echo str_replace("DJIA", "", $entry->textContent." REGISTER DJIA here");

代替:

echo trim($entry->textContent);  // use `trim` to eliminate spaces
echo str_replace("DJIA", "", "REGISTER DJIA here");