在過去的幾個小時裏,我一直在使用正則表達式。我從來不敢把手放在這上面,所以請和我一起裸照。preg_match_all question
Basicly我試圖從下面的源
<random htmlcode here>
<td style="BORDER-RIGHT-STYLE:none;">
<a id="dgWachtlijstFGI_ctl03_hlVolnaam" title="Klant wijzigen" class="wl" href="javascript: Pop(600,860,'klantwijzig','FrmKlant.aspx','? Wijzig=true&lcSchermTitel=&zoekPK=+++140+12++8',false,true); ">FIRST LINE A</a>
(SECOND LINE A)<br>
THIRD LINE A </td>
<random htmlcode here>
<td style="BORDER-RIGHT-STYLE:none;">
<a id="dgWachtlijstFGI_ctl04_hlVolnaam" title="Klant wijzigen" class="wl" href="javascript: Pop(600,860,'klantwijzig','FrmKlant.aspx','?Wijzig=true&lcSchermTitel=&zoekPK=+++140+12++8',false,true); ">FIRST LINE B</a>
(SECOND LINE B)<br>
THIRD LINE B </td>
<random htmlcode here>
什麼,我想出了這個遠一些信息如下(感謝rubular.com)
<?php $bestand = 'input.htm';
$fd = fopen($bestand,"r");
$message = fread($fd, filesize ($bestand));
$regexp = "FrmKlant.aspx.*\">(.*)<\/a>\s(.*)<br>\s(.*)\s\s(.*)";
if (preg_match_all("#$regexp#siU", $message, $matches))
{
print_r($matches);
}?
>
這其實似乎把我需要在一個多維數組中的第一和第二行。到目前爲止這麼好,因爲我想要一個多維數組。 但是,它似乎沒有捕獲第三行。不知何故它創建數組[4]
[1] => Array ([0] => FIRST LINE A [1] => FIRST LINE B)
[2] => Array ([0] => (SECOND LINE A) [1] => (SECOND LINE B))
[3] => Array ([0] => [1] =>) [4] => Array ([0] => [1] =>)
我正在尋找的是這樣的:
[0] => Array ([0] => FIRST LINE A [1] => FIRST LINE B)
[1] => Array ([0] => (SECOND LINE A) [1] => (SECOND LINE B))
[2] => Array ([0] => THIRD LINE A [1] => THIRD LINE B))
正如你可能已經注意到,我迷路了!任何幫助將不勝感激。
要閱讀整個文件的內容,看看http://php.net/manual/en/function.file-get-contents.php – 2010-06-24 06:32:19
大聲笑。不管我們說了多少次......他們總是問,呃? **不要使用正則表達式來解析html ** – mpen 2010-06-24 06:34:03