1
我需要一個正則表達式來提取指定的值,但不起作用。用RegEx提取特定輸出的具體數據
的HTML代碼是下一個:
<body style="background: #FFF; padding-left: 5px;">
<form name="form1" method="post" action="verify()" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/asdasfafasf/9Q2w==" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKb/LCHCALs0bLrBgKM54rGBulKe8VRM9SNhTfqyz0GubMFea7i" />
</div>
<div class="nicer">
<input name="TextBox1" type="text" value="asdf44" id="TextBox1" placeholder="Ingresa tu patente" />
</div>
<p class="sample">
<br /> sample: asdasd34 ó ABCD12
<br /> Para . Ej. AB<strong style="font-weight: bold !importand;">0</strong>123</p>
<p>
<input type="submit" name="Button1" value="Consultar" id="Button1" class="button orange_btn small_btn" />
</p>
<h3><span id="Label1" class="infractions_report">result: asdf44</span></h3>
<div>
<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
<tr>
<th scope="col">date</th>
<th scope="col">category</th>
<th scope="col">statusok</th>
</tr>
<tr class="txt">
<td>10-08-2015</td>
<td>1</td>
<td>cs nor</td>
</tr>
<tr class="txt">
<td>04-08-2015</td>
<td>1</td>
<td>cs nor2</td>
</tr>
<tr class="txt">
<td>01-08-2015</td>
<td>1</td>
<td>cs nor3</td>
</tr>
<tr class="txt">
<td>30-07-2015</td>
<td>1</td>
<td>cs nor4</td>
</tr>
<tr class="txt">
<td>19-06-2015</td>
<td>1</td>
<td>cn nor5</td>
</tr>
</table>
</div>
</form>
</body>
PHP代碼是下一個:
$expresiondate = '/\<tr\>[\s]*\<td class\=\"txt\"\>[\s]*([^\s\<\/]*)/is';
preg_match_all($expresiondate , $buffer, $exit1);
$expresionCategory= '/\-[\d]{4}[\s]*<\/td\>[\s]*\<td class\=\"txt\"\>[\s]*([^\s\<\/]*)/is';
preg_match_all($expresionCategory, $buffer, $exit2);
$expresionstatus= '/\>[\s]*[\d]*[\s]*<\/td\>[\s]*\<td class\=\"txt\"\>[\s]*([^\s\<\/]*)/is';
preg_match_all($expresionstatus, $buffer, $exit3);
我所需要的結果是下一個(例如值,但這個輸出):
1. date:
array (
0 =>
array (
0 => '<td align="center">15/01/2016 00:22:16</td>',
1 => '<td align="center">16/01/2016 00:22:16</td>',
2 => '<td align="center">11/01/2015 00:22:16</td>',
),
1 =>
array (
0 => '15/01/2016',
1 => '16/01/2016',
2 => '11/01/2015',
),
)
2. category
array (
0 =>
array (
0 => '<td>10-08-2015</td><td>1</td><td>cs nor</td>',
1 => '<td>10-08-2015</td><td>1</td><td>cs nor</td>',
2 => '<td>10-08-2015</td><td>1</td><td>cs nor</td>',
),
1 =>
array (
0 => '1',
1 => '1',
2 => '1',
),
)
3.status
array (
0 =>
array (
0 => '<td>10-08-2015</td><td>1</td><td>cs nor</td>',
1 => '<td>10-08-2015</td><td>1</td><td>cs nor</td>',
2 => '<td>10-08-2015</td><td>1</td><td>cs nor</td>',
),
1 =>
array (
0 => 'cn nor1',
1 => 'cn nor2',
2 => 'cn nor3,
),
)
謝謝,這幫助了我很多 –
PD我可以解析HTML絲毫的正則表達式;)看>/\
;)很高興我可以幫忙一下 –
再一次,正則表達式不是解析HTML的工具。使用專爲之設計的內置工具
DOMDocument
和DOMXPath
。來源
2016-02-18 01:15:03
相關問題