-5

I am trying to get the facebook page IDs from:

http://fanpagelist.com/category/top_users/view/list/sort/fans/page1

There's ~25 of them and they can be found by viewing the source code through the pattern /like_box.php?id=89562268312. https://graph.facebook.com/89562268312/picture, etc

<?php 
    $page = file_get_contents('http://fanpagelist.com/category/top_users/view/list/sort/fans/page1');
    preg_match_all('graph.facebook.com,picture', $page, $result, PREG_SET_ORDER);
    foreach ($result as $row) {
        echo "<p><b>$row[1]</b> $row[2]</p>\n";
    }
?>

The problem is i'm not trying to scrape a tag but a pattern.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • 4
    `'graph.facebook.com,picture'` isn't a regex. – gen_Eric Nov 15 '12 at 16:58
  • i either get errors or a blank page. what should i put in there then? – Thomasj Romns Nov 15 '12 at 17:03
  • * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Nov 15 '12 at 17:20

1 Answers1

1

You should be good with:

preg_match_all('#(?:(?<=\bhref="/like_box\.php\?id=)|' .
                '(?<=\bsrc="https://graph\.facebook\.com/))\d+#i',
                $page, $result, PREG_PATTERN_ORDER);

See this demo.

Ωmega
  • 42,614
  • 34
  • 134
  • 203