[REQUEST/HELP]Runescape News

Everything PHP-related! Discuss scripts, host challenges, request a script, or just ask for plain old help.

Moderators: IRC Operators, Support Team

Mhhhmmhhmmhh
Newbie
Newbie
Posts: 8
Joined: Wed Jan 17, 2007 10:03 pm
Location: Alabama
Contact:

[REQUEST/HELP]Runescape News

Postby Mhhhmmhhmmhh » Mon Apr 06, 2009 3:01 am

does anybody have a code/have any tips that will let me extract news from the Runescape Homepage to my own website. I can't figure out how to work cURL. Any help is appreciated. Thanks!
User avatar
Louis
User
User
Posts: 99
Joined: Mon Oct 29, 2007 2:53 am
Contact:

Re: [REQUEST/HELP]Runescape News

Postby Louis » Mon Apr 06, 2009 6:12 am

Here is a simple way to do it.
Note: I used multiple error array names so people can find out what is returning an error.

Code: Select all

<?php
/* Parse the runescape front page, and extract the data into an array. */
if ($file = file_get_contents('http://runescape.com/')) {
   $file = str_replace("\n","",$file);
   if (@preg_match('/<div class="newsTitle"><h3>(.*?)<\/h3><span>(.*?)<\/span><\/div>/',$file,$data) == 1) {
      $news["name"] = $data[1]; // news title
      $news["date"] = $data[2]; // news date
    } else {
      $news["err_1"] = true; // Could not get date and title
   }
   if (@preg_match('/<div class="newsDesc"><p>(.*?)<a href="(.*?)">Read more...<\/a><\/p><\/div>/',$file,$data) == 1) {
      $news["desc"] = $data[1]; // news desc
      $news["link"] = $data[2]; // news link
    } else {
      $news["err_2"] = true; // could not get description or link
   }
 } else {
   $news["err_3"] = true; // could not connect to runescape
}

/* Example usage of this data. */
if (isset($news["err_1"]) || isset($news["err_2"]) || isset($news["err_3"])) {
   echo "There was an error parsing news data.";
 } else {
   echo "[Runescape News] Name: ".$news["name"]." | Date: ".$news["date"]." | Description: ".$news["desc"]." | Link: ".$news["link"];
}
?>
Image
Get your LastFM signature here!
Mhhhmmhhmmhh
Newbie
Newbie
Posts: 8
Joined: Wed Jan 17, 2007 10:03 pm
Location: Alabama
Contact:

Re: [REQUEST/HELP]Runescape News

Postby Mhhhmmhhmmhh » Mon Apr 06, 2009 9:19 pm

Wow! Thank you very much! Great code!!

Return to “PHP”

Who is online

Users browsing this forum: No registered users and 1 guest