1 2 3 4 5 6 7 8 9 10 11 12 13 | <code><table width= "100%" border= "0" >
<tbody>
<tr>
<td class = "line" width= "18" align= "middle" >
<img src= "../images/yt/d.gif" style= "max-width:90%" style= "max-width:90%" alt= "php正则表达式匹配a标签" >
</td>
<td class = "line" align= "left" ><a class = "newslink" href= "xxxxx?id=1624" title= "xxxx" target= "_blank" >要匹配的内容</a></td>
<td class = "line" width= "75" >
<div class = "STYLE1" align= "right" >要匹配的内容</div>
</td>
</tr>
</tbody>
</table></code>
|
Copier après la connexion
Copier après la connexion
其中href中的id的具体值要匹配到,还有a标签的值,还有后面的div中的内容也要匹配。
感觉好复杂,求大神帮忙。
回复内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <code><table width= "100%" border= "0" >
<tbody>
<tr>
<td class = "line" width= "18" align= "middle" >
<img src= "../images/yt/d.gif" style= "max-width:90%" style= "max-width:90%" alt= "php正则表达式匹配a标签" >
</td>
<td class = "line" align= "left" ><a class = "newslink" href= "xxxxx?id=1624" title= "xxxx" target= "_blank" >要匹配的内容</a></td>
<td class = "line" width= "75" >
<div class = "STYLE1" align= "right" >要匹配的内容</div>
</td>
</tr>
</tbody>
</table></code>
|
Copier après la connexion
Copier après la connexion
其中href中的id的具体值要匹配到,还有a标签的值,还有后面的div中的内容也要匹配。
感觉好复杂,求大神帮忙。
1 | <code>/<a>(.*?)/i</a></code>
|
Copier après la connexion
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <code><?php $string = "<table width= '100%' border= '0' >
<tbody>
<tr>
<td class = "line" width= "18" align= "middle" >
<img src= "../images/yt/d.gif" style= "max-width:90%" style= "max-width:90%" alt= "php正则表达式匹配a标签" >
</td>
<td class = "line" align= "left" ><a class = "newslink" href= "xxxxx?id=1624" title= "xxxx" target= "_blank" >要匹配的内容</a></td>
<td class = "line" width= "75" >
<div class = "STYLE1" align= "right" >要匹配的内容</div>
</td>
</tr>
</tbody>
";
$reg = "#.*(.*)(a|A)>.*<div class=" STYLE1 " align=" right ">(.*)</div>#isU" ;
preg_match( $reg , $string , $matchs );
$id = $matchs [2];
$content = $matchs [3];
$divContent = $matchs [5];</code>
|
Copier après la connexion
给个参考
preg_match_all("/<a.>(.*).*<div>(.*)/Uis", $str,$m);
<p class="answer fmt" data-id="1020000006006753">
</p>
<p>如果不会写正则 可以试试 phpquery 写法跟jquery差不多 哈哈</p>
</div></a.>