정규식 질문좀 드릴게요 ㅠ 채택완료
<code><tr class="active">
<th></th>
<th scope="row">소계</th>
<th></th>
<td align="right"><b>+6,200</b></td>
<td align="right"><b>-1,400</b></td>
<td></td>
</tr>
<tr class="bg-black">
<th></th>
<th scope="row">보유포인트</th>
<th></th>
<td align="right"><b>18,650</b></td>
<td></td>
<td></td>
</code>
이런코드가잇는데
<td align="right"><b> 겹치는부분이 너무많아서
18,650만 못뽑습니다.
<th scope="row">보유포인트</th> 이거부터 <td align="right"><b>
여기까지 검색하고 </b></td> 이사이 검색해서
18,650만 뽑을수 있는 방법이 있을까요?
예제좀 알려주세요 ㅠ
답변 4개
</p>
<p>$str = <<<HEREDOC
<tr class="active">
<th></th>
<th scope="row">소계</th>
<th></th>
<td align="right"><b>+6,200</b></td>
<td align="right"><b>-1,400</b></td>
<td></td>
</tr>
<tr class="bg-black">
<th></th>
<th scope="row">보유포인트</th>
<th></th>
<td align="right"><b>18,650</b></td>
<td></td>
<td></td>
HEREDOC;</p>
<p> </p>
<p>preg_match_all('@<th scope="row">보유포인트</th>.*?<td align="right"><b>(.*?)</b></td>@s', $str, $arr);</p>
<p>
print_r($arr);</p>
<p>/*</p>
<p>Array
(
[0] => Array
(
[0] => <th scope="row">보유포인트</th>
<th></th>
<td align="right"><b>18,650</b></td>
)</p>
<p> [1] => Array
(
[0] => 18,650
)</p>
<p>)</p>
<p>*/</p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
</p>
<p>$html = '<code><tr class="active"></p>
<p><th></th></p>
<p><th scope="row">소계</th></p>
<p><th></th></p>
<p><td align="right"><b>+6,200</b></td></p>
<p><td align="right"><b>-1,400</b></td></p>
<p><td></td></p>
<p></tr></p>
<p><tr class="bg-black"></p>
<p><th></th></p>
<p><th scope="row">보유포인트</th></p>
<p><th></th></p>
<p><td align="right"><b>18,650</b></td></p>
<p><td></td></p>
<p><td></td></p>
<p> </p>
<p></code>';</p>
<p>preg_match_all('/<b(.*?)>(.*?)<\/b>/i', $html, $p_match);</p>
<p> </p>
<p>print_r2($p_match);</p>
<p>Array</p>
<p>(
[0] => Array
(
[0] => <b>+6,200</b>
[1] => <b>-1,400</b>
[2] => <b>18,650</b>
)
[1] => Array
(
[0] =>
[1] =>
[2] =>
)
[2] => Array
(
[0] => +6,200
[1] => -1,400
[2] => 18,650
)
)</p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인