php 正则如何取td里面还有a标签值的方法?

不可以第二次拿到结果再去匹配,能不能用一行正则达到取值的效果?

html如下

    $html = '<td>123</td><td>456</td><td><a href="test">789</a></td>';
    $preg2 = "/<td.*?>(.*?)<\/td>/";
    preg_match_all($preg2, $html, $data);

打印效果

Array
(
    [0] => Array
        (
            [0] => <td>123</td>
            [1] => <td>456</td>
            [2] => <td><a href="test">789</a></td>
        )

    [1] => Array
        (
            [0] => 123
            [1] => 456
            [2] => <a href="test">789</a>
        )

)

正确的打印效果

Array
(
    [0] => Array
        (
            [0] => <td>123</td>
            [1] => <td>456</td>
            [2] => <td><a href="test">789</a></td>
        )

    [1] => Array
        (
            [0] => 123
            [1] => 456
            [2] => 789
        )

)
查看回复