0

Well this is the html code:

<?

    $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);

    ?>

But what I want is to get back the word text, which is the td in that cell where class is identify. Or maybe if it is easier when class is identify print 1, or if it is identify2 press 0.

So I wna tin pseudocode like this:

If class-identify print the td-class=first-td of that cell
steveax
  • 17,527
  • 6
  • 44
  • 59
ghostrider
  • 5,131
  • 14
  • 72
  • 120
  • 1
    Why not just use a *real* HTML-parsing tool? –  Jul 05 '12 at 21:56
  • [indeed](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – steveax Jul 05 '12 at 22:01

1 Answers1

1

I can recommend you to use xpath like in this example.

Fanda
  • 3,760
  • 5
  • 37
  • 56