Php Var_dump()显示字符串,echo()/print_r()不返回任何内容
我使用一个简单的HTMLDOM解析器库来解析带有DOCTYPE标记的URL。我能够访问所需的标签,但每当我回显或尝试存储结果时,它都不会显示任何内容。但是,var_dump()向我显示了所需的字符串Php Var_dump()显示字符串,echo()/print_r()不返回任何内容,php,html-parsing,simple-html-dom,Php,Html Parsing,Simple Html Dom,我使用一个简单的HTMLDOM解析器库来解析带有DOCTYPE标记的URL。我能够访问所需的标签,但每当我回显或尝试存储结果时,它都不会显示任何内容。但是,var_dump()向我显示了所需的字符串 require_once("simpledom.php"); $url="http://google.com"; $sPage = file_get_contents($url); $sPageContent = new simple_html_dom(); $sPageContent->l
require_once("simpledom.php");
$url="http://google.com";
$sPage = file_get_contents($url);
$sPageContent = new simple_html_dom();
$sPageContent->load($sPage);
$sObjects = $sPageContent->find('unknown');
foreach($sObjects as $sKey)
{
var_dump($sKey->_[4]); /*this var_dump shows the stuff */
$showres = $sKey->_[4]
}
/* this variable should hold the string but it shows nothing */
echo $showres;
尝试将值强制转换为字符串
$showres = (string)$sKey->_[4];
此外,你的回声在你的回路后面
echo htmlentities($showres);
将回显$showres
中的内容,并用HTML实体替换所有HTML标记,以便您可以查看字符串,而不让浏览器将其用作标记
不知道你想做什么 当输出
时,浏览器会将其作为元素读取,因此需要对
符号进行编码。PHP已经为此构建了一个函数
因此,您的代码应该是:
echo htmlspecialchars($showres);
在你的资料来源中会给你什么
<!doctype html>
var_dump向您显示的类型是什么?var_dump向我显示字符串“”(长度=15)您是否尝试在循环中回送,就像您正在执行var_dump?如果您仅在浏览器上回送,您将看不到任何内容。。。您到底想做什么?如果您想在循环中存储您解析的所有内容,您应该执行类似于
$showres.=$sKey->\u4]的操作代码>。如果不知道这是否是你想要的行为,试着通过编辑来澄清你的问题。就像你想要的输出…它是一个已经说过的字符串var\u dump向我显示字符串“”(长度=15)
。抱歉@David,它没有帮助