Jump to content

Recommended Posts

<?php

$rs = file_get_contents("http://runescape.com/index.ws");

$pos = strpos($rs, '<fieldset class="menu poll">');
$number = substr($rs, $pos + 1, 100);
$pos = strpos($number, '</fieldset>');
$number = substr_replace($number, '', $pos);

echo $number; 

?>

 

Thats the code I'm using right now, but it dosn't work for the text I'm trying to get, the text is multi lined, this is the text:-

 

 

 

The words "What would you do #3" change every week, can anyone see something wrong in the code?

 

I just searched the string

<fieldset class="menu poll">

in the page's source code (FireFox's source code viewer has a search util) and it came up with nothing. In fact there seems to be no <fieldset> tags in the whole page. Which part of the page exactly are you trying to extract?

Here's what's going on. The website's page 'index.ws' checks to see if you have frames enabled. If so, you get redirected to 'title.ws'. Otherwise you get the following:

RuneScape - the massive online adventure game by Jagex Ltd

RuneScape
RuneScape is a massive 3d multiplayer adventure, with monsters
to kill, quests to complete, and treasure to win. You control your
own character who will improve and become more powerful the more you play.
This site uses frames, but your browser doesn't support them.
To play Runescape and browse our website, please download a recent web browser
such as Microsoft Internet Explorer or Mozilla Firefox.

The Jagex Team.

 

When you open 'index.ws' in PHP, the content you're looking for isn't there! it's actually in 'title.ws'. Here's some code that (I think) does what you want:

<?php
$rs = strip_tags(file_get_contents("http://runescape.com/title.ws"));

$str = get_between($rs, "Latest Poll", "Vote in this poll");
echo $str;

// gal_chen123's function
// pulled from http://www.php.net/manual/en/function.strpos.php
function get_between ($text, $s1, $s2) {
    $mid_url = "";
    $pos_s = strpos($text,$s1);
    $pos_e = strpos($text,$s2);
    for ( $i=$pos_s+strlen($s1) ; ( ( $i < ($pos_e)) && $i < strlen($text) ) ; $i++ ) {
        $mid_url .= $text[$i];
    }
    return $mid_url;
}
?>

 

Hope that helps.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.