Created
May 16, 2011 11:45
-
-
Save omundy/974304 to your computer and use it in GitHub Desktop.
Basic scraping demo with "regex" parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Basic scraping demo with "regex" parsing | |
* Owen Mundy Copyright 2011 GNU/GPL */ | |
$url = "http://www.bbc.co.uk/news/"; // 0. url to start with | |
$contents = file_get_contents($url); // 1. get contents of url in a string | |
// 2. match title | |
preg_match('/<title>(.*)<\/title>/i', $contents, $title); | |
print $title[1]; // 3. print result | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment