0
我使用preg_mach用於提取一些HTML(我嘗試使用DOM文檔,但我有一些問題,新行) 任何方式......這是我的代碼..提取與一些的preg_match HTML
1.HTML
<body>
<!-- icon and title -->
<div class="smallfont">
<img class="inlineimg" src="images/icons/icon1.gif" alt="" border="0" />
<strong>qrtoobah 3nwan</strong>
</div>
<hr size="1" style="color:#CCCCCC; background-color:#CCCCCC" />
<!--/icon and title -->
<div id="post_message_14142536">
<font size="7"><font color="red">msaha 700</font></font><br />
<font size="7"><font color="red">shamali 20</font></font><br />
<font size="7"><font color="red"> 1700 almetr</font></font><br />
<font size="7"><font color="#ff0000">sooom bs</font></font><br />
<font size="7"><font color="#ff0000">albee3 qreeb</font></font>
</div>
<!-- message -->
</body>
extract.php
<?php
$html = file_get_contents("1.html");
$pattern = '/<([!]+)([^]+).*>([^]+)(message\ \-\-\>)/';
preg_match($pattern, $html, $matches);
print_r($matches);
?>
我想<!-- icon and title -->)blablabla(<!--/message -->
之間的任何東西...... ,但我得到這個數組:
Array ([0] => [1] => ! [2] => -- [3] => message -->)
我認爲這個問題更加微不足道。右鍵單擊 - >查看源代碼。 'Array([0]'是什麼都不是,因爲它是一個html註釋,因此不會顯示。 – MarcDefiant
您還需要通過「s」或「m」(不知道哪個)修飾符才能使'.'匹配換行 – MarcDefiant
有沒有什麼辦法提取它..或提取上面的兩個div – aboji