PHP获取HTML标签

WBOY
Libérer: 2016-06-23 14:01:46
original
1665 Les gens l'ont consulté

<html><body><tr id="ASPxGridView1_DXDataRow0" class="dxgvDataRow_Soft_Orange">	<td class="dxgv">53</td>		<td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=外海&startm=&endtm=" target="_blank">1</a></td>		<td class="dxgv">2</td>		<td class="dxgv">3</td>		<td class="dxgv">4</td>		<td class="dxgv">6</td>		<td class="dxgv">7</td>		<td class="dxgv">8</td>		<td class="dxgv">9</td>		<td class="dxgv" style="border-right-width:0px;">10</td>	</tr>	<tr id="ASPxGridView1_DXDataRow1" class="dxgvDataRow_Soft_Orange">		<td class="dxgv">11</td>		<td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=j江苏&startm=&endtm=" target="_blank">12</a></td>		<td class="dxgv">13</td>		<td class="dxgv">14</td>		<td class="dxgv">15</td>		<td class="dxgv">16</td>		<td class="dxgv">17</td>		<td class="dxgv">18</td>		<td class="dxgv">19</td>		<td class="dxgv" style="border-right-width:0px;">20</td>	</tr>	<tr id="ASPxGridView1_DXDataRow1" class="dxgvDataRow_Soft_Orange">		<td class="dxgv">21</td>		<td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=上海&startm=&endtm=" target="_blank">22</a></td>		<td class="dxgv">23</td>		<td class="dxgv">24</td>		<td class="dxgv">25</td>		<td class="dxgv">26</td>		<td class="dxgv">27</td>		<td class="dxgv">28</td>		<td class="dxgv">29</td>		<td class="dxgv" style="border-right-width:0px;">30</td>	</tr></tr></body></html>	
Copier après la connexion


请教如何获得标签中的1~30这些值呢?最好用simple_html_dom来获取?知道的朋友说下哦!如果不是用这个类也可以!


回复讨论(解决方案)

 $s=<<(\d+)()?#isU",$s,$m);print_r($m[1]);
Copier après la connexion

loadHTML($html);$tr = $dom->getElementsByTagName('tr');$str ='';foreach ($tr as $key => $value) {	$value = trim(str_replace(PHP_EOL, '', $value->nodeValue));	$value = preg_replace('/\s\s+/', '|', $value);		$value = substr($value, strrpos($value, '|')+1);	var_dump($value);	$str.=$value;}var_dump($str);?>
Copier après la connexion

$dom  = new  DOMDocument ;$dom->loadHTML($html);$tr = $dom->getElementsByTagName('tr');$str ='';foreach ($tr as $key => $value) {	$value = trim(str_replace(PHP_EOL, '', $value->nodeValue));	$value = preg_replace('/\s\s+/', ',', $value);		$str.=$value.',';}$str = substr($str, 0,-1);var_dump($str);
Copier après la connexion

$s =<<< HTML<html><body><tr id="ASPxGridView1_DXDataRow0" class="dxgvDataRow_Soft_Orange">    <td class="dxgv">53</td>        <td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=外海&startm=&endtm=" target="_blank">1</a></td>        <td class="dxgv">2</td>        <td class="dxgv">3</td>        <td class="dxgv">4</td>        <td class="dxgv">6</td>        <td class="dxgv">7</td>        <td class="dxgv">8</td>        <td class="dxgv">9</td>        <td class="dxgv" style="border-right-width:0px;">10</td>    </tr>    <tr id="ASPxGridView1_DXDataRow1" class="dxgvDataRow_Soft_Orange">        <td class="dxgv">11</td>        <td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=j江苏&startm=&endtm=" target="_blank">12</a></td>        <td class="dxgv">13</td>        <td class="dxgv">14</td>        <td class="dxgv">15</td>        <td class="dxgv">16</td>        <td class="dxgv">17</td>        <td class="dxgv">18</td>        <td class="dxgv">19</td>        <td class="dxgv" style="border-right-width:0px;">20</td>    </tr>    <tr id="ASPxGridView1_DXDataRow1" class="dxgvDataRow_Soft_Orange">        <td class="dxgv">21</td>        <td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=上海&startm=&endtm=" target="_blank">22</a></td>        <td class="dxgv">23</td>        <td class="dxgv">24</td>        <td class="dxgv">25</td>        <td class="dxgv">26</td>        <td class="dxgv">27</td>        <td class="dxgv">28</td>        <td class="dxgv">29</td>        <td class="dxgv" style="border-right-width:0px;">30</td>    </tr></tr></body></html>HTML;include 'simple_html_dom.php';$p = str_get_html($s);foreach($p->find('td') as $i=>$r) {  if($i) echo $r->text(), PHP_EOL;}
Copier après la connexion
Copier après la connexion
1
2
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

$s =<<< HTML<html><body><tr id="ASPxGridView1_DXDataRow0" class="dxgvDataRow_Soft_Orange">    <td class="dxgv">53</td>        <td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=外海&startm=&endtm=" target="_blank">1</a></td>        <td class="dxgv">2</td>        <td class="dxgv">3</td>        <td class="dxgv">4</td>        <td class="dxgv">6</td>        <td class="dxgv">7</td>        <td class="dxgv">8</td>        <td class="dxgv">9</td>        <td class="dxgv" style="border-right-width:0px;">10</td>    </tr>    <tr id="ASPxGridView1_DXDataRow1" class="dxgvDataRow_Soft_Orange">        <td class="dxgv">11</td>        <td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=j江苏&startm=&endtm=" target="_blank">12</a></td>        <td class="dxgv">13</td>        <td class="dxgv">14</td>        <td class="dxgv">15</td>        <td class="dxgv">16</td>        <td class="dxgv">17</td>        <td class="dxgv">18</td>        <td class="dxgv">19</td>        <td class="dxgv" style="border-right-width:0px;">20</td>    </tr>    <tr id="ASPxGridView1_DXDataRow1" class="dxgvDataRow_Soft_Orange">        <td class="dxgv">21</td>        <td class="dxgv"><a class="dxeHyperlink" href="onest.aspx?stnm=上海&startm=&endtm=" target="_blank">22</a></td>        <td class="dxgv">23</td>        <td class="dxgv">24</td>        <td class="dxgv">25</td>        <td class="dxgv">26</td>        <td class="dxgv">27</td>        <td class="dxgv">28</td>        <td class="dxgv">29</td>        <td class="dxgv" style="border-right-width:0px;">30</td>    </tr></tr></body></html>HTML;include 'simple_html_dom.php';$p = str_get_html($s);foreach($p->find('td') as $i=>$r) {  if($i) echo $r->text(), PHP_EOL;}
Copier après la connexion
Copier après la connexion
1
2
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
非常感谢LZ!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal