我在php 5.5.8上有一个简单的html dom问题。我有这样的代码:
//Getting page content
$t=$this->curl->getResponse();
//Show page content
echo $t;
//Parse with simple html dom and show result
$dm=str_get_html($t);
echo $dm->save();
运行代码后,我看到了
echo $t;
返回类似的内容:
<output omitted>
<span style="display:block;">ORGANIZATION CODE:123456789ABCD</span></div>
</div><br><div id="pageTitle">
<h1>Select your flights</h1>
</div>
<div id="yellowheader"></div>
<div id="navDiv">
<ol id="tripmeter">
<ul><span class="tripmeterNotSelected"><a href="AS.aspx" onclick="S.DisplayLoadingBar();">Search Flight</a></span></ul>
<ul id="tripmeterLink"><span id="tripmeterSelected">Select Flight</span><div id="tripmeterTail"></div>
</ul>
<ul><span class="tripmeterNotSelected">Guest Details</span></ul>
<ul><span class="tripmeterNotSelected">Add-Ons</span></ul>
<ul><span class="tripmeterNotSelected">Payment</span></ul>
<ul><span class="tripmeterNotSelected">Itinerary Receipt</span></ul>
</ol>
</div>
</div>
<div id="selectMainBody" class="main">
<div id="errorDiv"></div><input type="hidden" name="xxxxxxxxxxx" id="xxxxxxxx"><div id="tourBasingDialog" style="display:block;"><br><center>
<output omitted>
虽然
echo $dm->save();
返回
<output omitted>
<span style="display:block;">ORGANIZATION CODE:123456789ABCD</span>
</div> </div><br></div>
<div id="selectMainBody" class="main"> <div id="errorDiv"></div>
<input type="hidden" name="xxxxxxxx" id="xxxxxxx">
<div id="tourBasingDialog" style="display:block;"><br>
EOF
正如您所看到的,在str_get_html()之后,save()页面内容发生了变化和切割。为什么会这样?
答案 0 :(得分:0)
您在某些时候遗漏了某些内容,但Simple HTML Dom Parser
正常工作。
我将你的html复制到文件中,使用file_get_contents('content.htm');
加载该文件并打印出来。
因此,在调用$html->save();
后显示并获得相同的输出。
require_once 'dom.php';
$html = file_get_contents('content.htm');
echo "<h2>Complete File</h2>";
echo $html ;
$html = str_get_html($html);
echo "<hr />";
echo "<h2>After calling save()</h2>";
echo $html->save("dump.html"); //save stuff to dump.html file
这给了我这个输出
dump.html