Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $file = 'http://www.winknews.com/2015/08/06/4-rescued-from-overnight-house-fire-in-naples/';
- // the following line prevents the browser from parsing this as HTML.
- //header('Content-Type: text/plain');
- // get the file contents, assuming the file to be readable (and exist)
- $contents = file_get_contents($file);
- $contents = str_replace("<", "\n<", $contents);
- $title = getTitle($contents);
- print "$title<br>";
- $img = getIMG($contents);
- print "$img<br>";
- function getIMG($contents){
- $searchfor = 'og:image';
- // escape special characters in the query
- $pattern = preg_quote($searchfor, '/');
- // finalise the regular expression, matching the whole line
- $pattern = "/^.*$pattern.*\$/m";
- preg_match_all($pattern, $contents, $matches);
- $img = implode("\n", $matches[0]);
- $img = explode('"', $img);
- return "$img[3]";
- }
- function getTitle($contents){
- $searchfor = '<title>';
- // escape special characters in the query
- $pattern = preg_quote($searchfor, '/');
- // finalise the regular expression, matching the whole line
- $pattern = "/^.*$pattern.*\$/m";
- preg_match_all($pattern, $contents, $matches);
- $title = implode("\n", $matches[0]);
- $title = explode('>', $title);
- $title = explode('<', $title[1]);
- return "$title[0]";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement