PHP parsing regular expression to take code from html source?

yiui

New member
hey I have a php script that opens a URL of another another website and reads in the HTML to a variable.

<tr>
<td class="bold">Your name</td>
<td class="boldblack">Bill</td>
</tr>

Is there a regular expression or something that could extract the persons name between the td tags, in the above code example I would want Bill returned. Any help would be grateful
 
<td[^>]*>([^<]+)

This will extract the "Your name" and "Bill" strings. You could add a space behind the second to last character in the regex above to limit the example you gave us to just "Bill", but a better way to limit it would be changing the html to include

<td id="name" class="boldblack...

and then changing the regex to this

<td([^i]|i[^d])*id="name"[^>]*>([^<]+)

which means
1. look for <td
2. skip everything that isn't an i or, if it is an i, is not followed by a d
3. look for the id="name" tag you added for the specific field you're looking for
4. skip everything until the closing brace
5. capture the name
 
Back
Top