PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
BASiQ
Forum Newbie
Posts: 4 Joined: Mon Jan 30, 2012 10:11 pm
Post
by BASiQ » Mon Jan 30, 2012 10:13 pm
have this code which parses out a div from within the page gotten. Works great.
Code: Select all
$html = file_get_dom('http://steamcommunity.com/profiles/76561198010758659/games?tab=all');
echo $html('div#game_440 h5', 0)->getPlainText();
but I need the code to parse from multiple links, instead of using one link like it does now. I would like these multiple links to be called from a text file.
How would I go about this? I know about the file() function. but I have no idea how to use it. The examples are all wrong
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Jan 31, 2012 5:36 am
What are the file contents like? One such link per line? If so, you could loop through it using
fgets() then call your file_get_dom function from within the loop.
BASiQ
Forum Newbie
Posts: 4 Joined: Mon Jan 30, 2012 10:11 pm
Post
by BASiQ » Tue Jan 31, 2012 8:31 am
After some time, I got this
Code: Select all
$lines = file('array.htm');
foreach ($lines as $line) {
$html = file_get_dom($line);
echo $html('div#game_440 h5', 0)->getPlainText();
echo " ";
echo "$line";
echo "<br/>";
}
but the line
Code: Select all
echo $html('div#game_440 h5', 0)->getPlainText();
gets me this error when using simple_html_dom.php
"Fatal error: Function name must be a string in /home/MySite/public_html/parse/index.php on line 47"
If I use ganon.php it works fine, but is super slow. Any ideas?
BASiQ
Forum Newbie
Posts: 4 Joined: Mon Jan 30, 2012 10:11 pm
Post
by BASiQ » Tue Jan 31, 2012 10:46 am
Finished product for reference
Code: Select all
<?php
include('simple_html_dom.php');
$lines = file('array.htm');
foreach ($lines as $line) {
$html = file_get_dom($line);
$divline = $html->find('div[id=game_440] h5', 0);
$divline = preg_replace('/(<h5>)/i', '', $divline);
$divline = preg_replace('/(<\/h5>)/i', '', $divline);
echo $divline;
echo " - ";
echo "$line";
echo "<br>";
$html->clear();
unset($html);
}
array.htm is merely a text file with lines of steam profile links.
BASiQ
Forum Newbie
Posts: 4 Joined: Mon Jan 30, 2012 10:11 pm
Post
by BASiQ » Tue Jan 31, 2012 10:56 am
Final revised code cleaning up stuff
Code: Select all
<?php
include('simple_html_dom.php');
$lines = file('array.htm');
foreach ($lines as $line) {
$html = file_get_dom($line);
$divline = $html->find('div[id=game_440] h5', 0);
$divline = preg_replace('/(<h5>)/i', '', $divline);
$divline = preg_replace('/(<\/h5>)/i', '', $divline);
echo $divline." ".$line."<br>";
$html->clear();
unset($html);
}
?>