2015-10-19 30 views
1

我有一個簡單的PHP DOM 5.5.8的DOM DOM的問題。我有這樣的代碼:簡單的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()頁面內容改變和切割後。爲什麼發生?

+1

垃圾中的dump.html

enter image description here

,垃圾出基本。該HTML是一個混亂開始。 – pguardiario

回答

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 

這給了我這個輸出輸出

enter image description here