I have a sample code:
$content = '
<table width="100%" border="0">
<tr>
<td style="white-space:nowrap;" class="cap_row_odd">browser_id</td>
<td width="100%" class="cap_row_odd">browser_winmo_iemobile9</td>
</tr>
<tr>
<td style="white-space:nowrap;" class="cap_row_even cap_isempty"><span>nokia_feature_pack</span></td>
<td width="100%" class="cap_row_even cap_isempty"></td>
</tr>
</table>
';
And I using DOMDocument:
$dom = new DOMDocument();
@$dom->loadHTML($content);
$xpath = new DOMXPath($dom);
$attributes = array();
$query1 = $xpath->query("//td[@style='white-space:nowrap']");
foreach($query1 as $a) {
$attributes[] = $a->nodeValue;
}
print_r($attributes);
=> But result is null, How to get it?
You missing a
;from the xpath query:Consider using the contains() function to make your query more robust: