ghostrider
ghostrider

Reputation: 5259

using regular expression in HTML parsing in php

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

Upvotes: 0

Views: 132

Answers (1)

Fanda
Fanda

Reputation: 3786

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

Upvotes: 1

Related Questions