devWhiz Posted April 28, 2011 Share Posted April 28, 2011 $lastfm = file_get_contents('http://www.last.fm/group/Rishloo/members'); $users = explode('" id="r4_', $lastfm); $users = explode('">', $users[1]); var_dump($users[0]); that is only echoing one ID http://www.last.fm/group/Rishloo/members 1 id for each member it should be echoing.. any idea why it isnt? $lastfm = file_get_contents('http://www.last.fm/group/Rishloo/members'); $grab_id=explode('" id="r4_', $lastfm); for($b=1; $b<count($grab_id); $b++){ $getid=explode('">', $grab_id[$b]); echo count($getid[0]); } that echos all 1's.. any help is appreciated.. thanks thanks Quote Link to comment Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 can you do a var_dump on $grab_id? and tell the number of array items? <?php var_dump($grab_id); ?> If that is only 1 than that is the problem i guess. Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 28, 2011 Author Share Posted April 28, 2011 it just echos the contents of http://www.last.fm/group/Rishloo/members it looks like... Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 28, 2011 Share Posted April 28, 2011 You may be better of using the Document Object Model. Or better yet regex rather than explode. Regex is a lot more powerful. Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 28, 2011 Author Share Posted April 28, 2011 do you have any code examples I can look at? Quote Link to comment Share on other sites More sharing options...
fugix Posted April 28, 2011 Share Posted April 28, 2011 he linked the text to where you should see examples Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 28, 2011 Share Posted April 28, 2011 I assumed you want more than just the IDs. The following code will provide the id, image url, name(s), bio for each user, plus their listening or last track info. $lastfm = file_get_contents('http://www.last.fm/group/Rishloo/members'); $pattern = array(); $patterns[] = "id=\"r4_([^\"]*)\""; $patterns[] = "class=\"userImage\"><img.*?src=\"([^\"]*)\""; $patterns[] = "<\/span> ([^<]*)<"; $patterns[] = "<strong class=\"fn\">([^<]*)<"; $patterns[] = ", ([^\n]*)"; $patterns[] = "(Listening|Last track):"; $patterns[] = "<a href=\"\/music\/[^\"]*\">([^<]*)<"; $patterns[] = "<a href=\"\/music\/[^\"]*\">([^<]*)<"; $pattern = "#" . implode('.*?', $patterns) . "#sim"; preg_match_all($pattern, $lastfm, $matches, PREG_SET_ORDER); //Remove first element from each record, it contains HTML code that will mess up the output //This is not needed and only included so I can print_r the results to the page foreach($matches as $idx => $value) { unset($matches[$idx][0]); } echo "<pre>\n"; print_r($matches) This is probably not the most efficient way to get that data, but it works. Here is some of the output from the above: Array ( [0] => Array ( [1] => 20770702 [2] => http://userserve-ak.last.fm/serve/64s/60856343.jpg [3] => Alice_in_pains [4] => nermin [5] => 20, Female, Azerbaijan [6] => Last track [7] => Tool [8] => Useful Idiot ) [1] => Array ( [1] => 35133964 [2] => http://userserve-ak.last.fm/serve/64s/55291785.jpg [3] => agostinoo [4] => Agostino [5] => 19, Male, United Kingdom [6] => Last track [7] => Cat Power [8] => Fool ) [2] => Array ( [1] => 38461866 [2] => http://userserve-ak.last.fm/serve/64s/61233861.jpg [3] => maverikgameface [4] => Reece Gerard [5] => 20, United States [6] => Last track [7] => A Perfect Circle [8] => Weak And Powerless ) Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 28, 2011 Share Posted April 28, 2011 OK, after some further verification it looks like the above expressions were preventing some records to be properly identified. I don't have the time to evaluate all the records to determine the problem. Just comment out the lines identified below and you should get the ID, image URL and name of each user. I can't guarantee it will always work based upon how that website modifies their data $pattern = array(); $patterns[] = "id=\"r4_([^\"]*)\""; $patterns[] = "class=\"userImage\"><img.*?src=\"([^\"]*)\""; $patterns[] = "<\/span> ([^<]*)<"; //$patterns[] = "<strong class=\"fn\">([^<]*)<"; //$patterns[] = ", ([^\n]*)"; //$patterns[] = "(Listening|Last track):"; //$patterns[] = "<a href=\"\/music\/[^\"]*\">([^<]*)<"; //$patterns[] = "<a href=\"\/music\/[^\"]*\">([^<]*)<"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.