But anyway, to deal with information in a more general way for the info/time parts (such as changing what tags it's inside from small to something else), I created a general purpose function to retrieve that information.
Output for time and info:
Array ( [0] => 07/25/2009 [1] => at 1:50pm )
Array ( [0] => Halo 3 - joinable [1] => Custom Games Infection [2] => 51 of 79 achievements, 1110 of 1750 pts )
The code in full:
<?php
/* Descend the tree depth first and pre visit all nodes. */
function depthFirstPreVisitAll($node) {
$text = array();
// Visit all the child nodes of this node
foreach($node->childNodes as $child) {
$tmp = array();
// If this child has child nodes of its own, visit them by recursion
if ($child->hasChildNodes()) {
$tmp = depthFirstPreVisitAll($child);
/* Since we keep going deeper, the returned results may be an array.
Unless we flatten it, we'll end up with a multidimensional array like this:
Array ( [0] => Halo 3 - joinable
[1] => Array ( [0] => Custom Games Infection
[1] => Array ( [0] => 51 of 79 achievements, 1110 of 1750 pts )
)
) */
if (is_array($tmp)) {
foreach ($tmp as $t)
$text[] = $t;
}
else
$text[] = $tmp;
}
else if ($child->nodeName == "#text")
$text[] = $child->textContent;
}
return $text;
}
$file = "...";
$d = new DOMDocument();
$d->loadHTMLFile($file);
$rowG1 = $d->getElementById('content')->childNodes->item(1)->childNodes->item(1);
if($rowG1 !="") {
$imgs = $rowG1->getElementsByTagName('img');
$data = array();
foreach ($imgs as $img) {
if ($img->attributes) {
$src = $img->attributes->getNamedItem("src")->value;
$title = $img->attributes->getNamedItem("title")->value;
if (stripos($src, "status") !== false)
$data['status'] = $title; // offline, online
else if (stripos($src, "flags") !== false) {
$data['country'] = $title;
$info = $img->parentNode->parentNode->lastChild->previousSibling;
$time = $info->previousSibling->previousSibling;
$data['time'] = depthFirstPreVisitAll($time);
$data['info'] = depthFirstPreVisitAll($info);
}
}
}
}
print_r($data['time']); echo "<br/>";
print_r($data['info']);
?>
And the above was used with the html code below. Do note that I've prepended it with doctype, html head, meta and body tags, as well as appended closing tag for body and html. If no meta tag is given, DOM parses input as if it's ISO 8859-1 (latin-1). So it's a good idea to set a meta tag for content type to match input encoding.
Apart from that, the only thing I did manually was cut out the superflous </font> tag that followed Halo 3 - joinable in your code. Copy paste error on your part? Because errors like that doesn't sit well with the PHP5 DOM parser.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type: text/html; charset=utf-8" />
</head>
<body>
<div id="content">
<table class="dottedhorizontal" width="100%">
<tr>
<th class="dottedhorizontal" width="140" colspan="4">Gamer Information</th>
<th class="dottedhorizontal center" width="30">Gamer<br />score</th>
<th class="dottedhorizontal center" width="60">Last Seen</th>
<th class="dottedhorizontal" width="*">Last Activity or Game Played </th>
</tr>
<tr>
<td class="dottedhorizontal"><img src="images/icons/status/online.png" width="16" height="16" alt="online" title="online"></td>
<td class="dottedhorizontal center">
<span style="position:relative;">
<span id="Gamer.img" class="hover">
<img src="http://avatar.xboxlive.com/avatar/Gamer/avatarpic-l.png" height="64" width="64" border="0" alt="" title="" />
</span>
<a href="javascript:void(0);" onMouseover="ShowHover('Gamer.img');" onMouseout="HideHover('Gamer.img');">
<img src="http://avatar.xboxlive.com/avatar/Gamer/avatarpic-l.png" height="20" width="20" border="0" alt="" title="" />
</a>
</span>
</td>
<td class="dottedhorizontal"><img src="images/icons/flags/gb.png" width="16" height="11" alt="United Kingdom" title="United Kingdom"></td>
<td class="dottedhorizontal">
<small>
<a href="http://live.xbox.com/member/Gamer" target="_blank" >Gamer</a>
<span style="position:relative;">
<span id="Gamer" class="popup">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="35" style="border-top: none;"><strong>Name: </strong></td>
<td width="*" style="border-top: none;">Wood</td>
</tr>
<tr>
<td width="35" style="border-top: none;"><strong>From: </strong></td>
<td width="*" style="border-top: none;">London, United Kingdom</td>
</tr>
<tr>
<td width="35" style="border-top: none;"><strong>Motto: </strong></td>
<td width="*" style="border-top: none;"></td>
</tr>
<tr>
<td width="35" style="border-top: none;" valign="top"><strong>Bio: </strong></td>
<td width="*" style="border-top: none;"></td>
</tr>
</table>
</span>
(<a href="javascript:void(0);" onMouseover="ShowPop('Gamer');" onMouseout="HidePop('Gamer');">bio</a>)
</span>
</small>
</td>
<td class="dottedhorizontal right"><small>7436</small></td>
<td class="dottedhorizontal center"><small>07/25/2009<br />at 1:50pm</small></td>
<td class="dottedhorizontal">
Halo 3 - joinable
<br />
<small>Custom Games Infection
<br />
<small>
51 of 79 achievements, 1110 of 1750 pts
</small>
</small>
</td>
</tr>
</table></div>
</body>
</html>
As for the [] not supported for strings, it seems to me you did
$data['info'] = $somenode->textContent, which means $data['info'] would be a string instead of an array.
The first assignment would have had to be $data['info'][] = $somenode->textContent to be able to use [] operator later on as well.