0
<?php 
    $contents = file_get_contents('link here');
    $doc = new DOMDocument();
    @$doc->loadHTML($contents);
    $xpath = new DOMXPath($doc);
    $xquery = '//tr[td[a]]';           
    $links = $xpath->query($xquery);   
    foreach ($links as $el) {
        $string = ($doc->saveHTML($el));
        preg_match('/<a class="LN" href=".*" onclick=".*">(.*)<\/a>/i', $string, $name); 
        preg_match('/<td align="center">.*\s*<\/td>\s*<td>(.*)<\/td>/i', $string, $locations);
        echo strip_tags($name[1]).' '.strip_tags($locations[1]);
    } 
?>

私の $string の値は

  <tr>
<td>
1.
 </td>
<td>
<a class="LN" href="" onclick="">
<b>Aaberg, Aaron E</b></a>
</td>
<td align="center">
54 
</td>
<td><a href="">Anchorage, AK</a><br />
<a href="">Nondalton, AK</a><br />
</td>
<td> </td><td><a href="">
                    View Details
                  </a></td></tr>

$location[i] を取得できないのはなぜですか?

4

2 に答える 2

0

それ以外の

preg_match('/<td align="center">.*\s*<\/td>\s*<td>(.*)<\/td>/i', $string, $locations);

あなたが使用することができます

preg_match('/<a href="">(.+)<\/a><br \/>/i', $string, $locations)
于 2013-09-07T08:56:50.633 に答える