Search code examples
phppreg-match

preg_match_all data from other site


f.e we have tr,td like this and i want use preg_match_all to select some data

<tr data-tag="tagid1" class="role-odd" role="row">
    <td class="sorting_1">pos</td>
    <td class="member_name" data-tag="tagid1">nick1</td>
    <td>rank1</td>
    <td>tagid2</td>
    <td class="right aligned">points</td>
    <td class="right aligned">lvl</td>
    <td data-sort="points">
        <img class="ui mini image" src="link" alt="desc">
    </td>
    <td class="right aligned" data-sort="points2">points2</td>
    <td class="right aligned" data-sort="points3">points3</td>
    <td>
        <div class="">
            <input id="compare-checkbox-tagid1" class="compareme" data-tag="tagid1" data-name="nick" type="checkbox">
        </div>
    </td>
</tr>
<tr data-tag="tagid2" class="role-even" role="row">
    <td class="sorting_1">pos</td>
    <td class="member_name" data-tag="tagid2">nick2</td>
    <td>rank2</td>
    <td>tagid2</td>
    <td class="right aligned">points</td>
    <td class="right aligned">lvl</td>
    <td data-sort="points">
        <img class="ui mini image" src="link">
    </td>
    <td class="right aligned" data-sort="points">points2</td>
    <td class="right aligned" data-sort="points3">points3</td>
    <td>
        <div class="">
            <input id="compare-checkbox-tagid2" class="compareme" data-tag="tagid2" data-name="nick" type="checkbox">
        </div>
    </td>
</tr>

if i use the following code

preg_match_all('#<tr[^>]+>(.+?)</tr>#ims',$out,$top);

$top contains all trs, but i don't need all data, i want the following data: pos,nick,rank,tagid,points,lvl,points2,points3

Can anyone help me?


Solution

  • Do you want get all contents from <td> ? You can try regular #<td.*?>(.*)<\/td>#