I don't really see any issues with your code that should cause you to run out of memory, at least not unless you are dealing with huge files. And since http://steamcommunity.com/profiles/76561198010758659/games?tab=all is only 74KB, your 128MB limit should be enough.
As such, I'd guess that the issue is with simple_html_dom. If you need to see what happens, use [man]memory_get_usage[/man] and echo memory usage to see where and when it's used up.
But if the issue is indeed with simple_html_dom, why not use something that works, at least as far as I know, such as PHP's built in [man]DOM[/man] functionality.
How to do the same thing using DOM. Maybe worth seeing if this works.
# The html file is full of markup errors
# This prevents those errors from being output to screen / sent to errorlog
# If you wish to inspect them, use libxml_get_errors()
libxml_use_internal_errors(true);
$lines = array('76561198010758659');
foreach ($lines as $usernumber)
{
$link = "http://steamcommunity.com/profiles/$usernumber/games?tab=all";
$d = new DOMDocument();
$d->loadHTMLFile($link);
$x = new DOMXPath($d);
# This XPath expression matches your CSS selector
$l = $x->query("//div[@id='game_440']//h5");
# Unless there can be zero or several h5 per id="game_440", this is always 1
if(count($l))
{
$hrs = (int) $l->item(0)->nodeValue;
if ($hrs < 150)
{
echo $hrs." - ".$link."<br>";
}
}
}
A few suggestions on improving the initial script
ini_set('memory_limit', '-1');
include('simple_html_dom.php');
$lines = file('array2.htm');
foreach ($lines as $usernumber)
{
# You claim this should remove "the stupid space", but is there really a space in
# $usernumber? If there is, do it directly to $usernumber
# If there isn't, then there isn't in the link below either and you can remove it
# completely. Moreover, the /m modifier should not be needed
# $link = preg_replace('/\s*','',$link);
/** Unnecessary work
$link = "http://steamcommunity.com/profiles/<sitenumber>/games?tab=all";
$link = preg_replace('/(<sitenumber>)/i',$usernumber,$link);
* since you can simply...
*/
$link = "http://steamcommunity.com/profiles/$usernumber/games?tab=all";
$html = file_get_dom($link);
//finds the div block and then the h5 line
$divline = $html->find('div[id=game_440] h5', 0);
# I'd get rid of $html as soon as possible, but unset($html) should be enough
# since that should automatically call the destructor. Still, I don't really see
# why this would be enough to cause you to run out of memory.
unset($html);
# maybe replace the pattern delimiter / with something else
# and remove ( and ) to make it more readable
# $divline = preg_replace('#</?h5>/i', '', $divline);
# However, since you know exactly what you want to remove, <h5> and </h5> respectively,
# and they never are changing or depend on anything else, it's more efficient to
$divline = substr($divline, 4, -5);
/* Since the line starts with a number and that's all you want to keep,
* it's simpler to just
* list($hrs,$u1,$u2,$u4) = explode(" ",$divline);
*/
$hrs = (int) $divline;
if ($hrs < 150)
{
echo $hrs." - ".$link."<br>"; //prints results
}
}