Skip to content

Instantly share code, notes, and snippets.

@omundy
Created May 16, 2011 11:45
Show Gist options
  • Save omundy/974304 to your computer and use it in GitHub Desktop.
Save omundy/974304 to your computer and use it in GitHub Desktop.
Basic scraping demo with "regex" parsing
<?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