我想保留div中所有内容与类内容(保持所有原始html格式包括对象flash视频)。但是当我使用SimpleHTMLDom进行解析时,我没有得到我想要的所有内容。
//File test.html
<div class="content">
<div style="text-align:center;">
<object id="fpt_player_3548_0" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="296" width="470"><param value="http://st.f2.vnecdn.net/f/v37/fptplayer_embed.swf" name="movie"><param value="high" name="quality"><param value="transparent" name="wmode"><param value="xmlPath=http://vnexpress.net/video/vne-info/id/3548/type/2&colorAux=0x0099ff&colorBorder=0x333333&colorMain=0xffffff&local=embed&mAuto=false&autoHide=false&trackurl=&tracktype=video" name="flashvars"><param value="true" name="allowfullscreen"><param value="always" name="allowScriptAccess"><embed id="fpt_player_3548_0" name="fpt_player_3548_0" src="http://st.f2.vnecdn.net/f/v37/fptplayer_embed.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" flashvars="xmlPath=http://vnexpress.net/video/vne-info/id/3548/type/2&colorAux=0x0099ff&colorBorder=0x333333&colorMain=0xffffff&local=embed&mAuto=false&autoHide=false&trackurl=&tracktype=video" height="296" width="470">
</object>
</div>
<p class="Normal">
<em>Something</em>
More contents
</p>
</div>
使用SimpleHTMLDom解析HTML的代码
$html = file_get_html('test.html');
// find all div tags with class=content
foreach($html->find('div.content') as $e)
echo $e->innertext . '<br>';
此输出我有(对象标签隐藏)
<div style="text-align:center;">
<div id="video-3548" data-component="true" data-component-type="video" data-component-value="3548" data-component-typevideo="2" style="display:none;">
</div>
</div>
<p class="Normal">
<em>Something</em>
More contents
</p>