Possible Duplicate:
How to parse and process HTML with PHP?
How would I go about getting a certain string from a webpage that has been scraped? I am using SimpleBrowser in PHP to download a webpage into a variable.
The resultant webpage at a certain part has the following:
<tr>
<td class="label" width="350">POD Receiver Name: </td>
<td class="field" align="left">
<b>KRISTY</b>
</td>
</tr>
I want to get the value KRISTY into a variable, but not really sure how. I have no real experience with regex so I wouldnt know where to start.
Any help appreciated!
To pull one specific part out from a known location, I'd use xpath. Try a tutorial such as http://ditio.net/2008/12/01/php-xpath-tutorial-advanced-xml-part-1/
I am not sure why you are storing a page in a variable. But if you have a page stored as a string in a variable you can use Regular expression to extract string out of it. For this particular example you can use something like this.
$v = '<tr>
<td class="label" width="350">POD Receiver Name: </td>
<td class="field" align="left">
<b>KRISTY</b>
</td>
</tr>';
preg_match('/\<b\>(.*?)\<\/b\>/', $v, $matches);
$result = $matches[1];
This particular regular expression gets everything between the bold tags.
If the structure can be depended on, give SimpleXML a shot:
$xml = simplexml_load_string(html_entity_decode($v));
$name = strval($xml->td[1]->b);//KRISTY