在php中使用正则表达式进行HTML解析

在php中使用正则表达式进行HTML解析,php,html,html-parsing,Php,Html,Html Parsing,这是html代码: <? $html ='<table cellspacing="0" cellpadding="0" class="mytable"> <tr> <th class="first-td">Home <span>Live</span>&l

这是html代码:

<?

    $html ='<table cellspacing="0" cellpadding="0" class="mytable">
                                         <tr>
                                            <th class="first-td">Home <span>Live</span></th>
                                            <th>type</th>
                                            <th>Status</th>

                                          </tr>
                                                                              <tr>
                                            <td width="40%" class="first-td">text1</td>
                                            <td>info</td>
                                            <td class="status"><span class="identify">asdf2</span></td>

                                          </tr>
                                                                                <tr>
                                            <td width="40%" class="first-td">text2</td>
                                            <td>info</td>
                                            <td class="status"><span class="identify2">asdf</span></td>
    ';

    $pattern = '/<span class="identify">(.*?)<\/span>/im';
    preg_match_all($pattern, $html, $matches);
    print_r($matches);

    ?>

我建议您像这样使用xpath。

为什么不使用真正的HTML解析工具呢?
If class-identify print the td-class=first-td of that cell