phpcode Posted August 11, 2007 Share Posted August 11, 2007 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/64392-solved-getting-multi-lined-text-from-a-website/ Share on other sites More sharing options...
php_tom Posted August 11, 2007 Share Posted August 11, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/64392-solved-getting-multi-lined-text-from-a-website/#findComment-321072 Share on other sites More sharing options...
phpcode Posted August 11, 2007 Author Share Posted August 11, 2007 Gave wrong link in the code, the link is http://www.runescape.com/title.ws (I just edited and tried the code still didn't work.) Quote Link to comment https://forums.phpfreaks.com/topic/64392-solved-getting-multi-lined-text-from-a-website/#findComment-321074 Share on other sites More sharing options...
php_tom Posted August 11, 2007 Share Posted August 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64392-solved-getting-multi-lined-text-from-a-website/#findComment-321096 Share on other sites More sharing options...
phpcode Posted August 11, 2007 Author Share Posted August 11, 2007 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/64392-solved-getting-multi-lined-text-from-a-website/#findComment-321120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.