phpcode Posted October 26, 2007 Share Posted October 26, 2007 I'm trying to get a certain part of a website and show it on my website but it doesn't work, can anyone see anything wrong with the code below? <?php error_reporting(E_ALL); 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; } $rs2 = strip_tags(file_get_contents("http://runescape.com/title.ws")); $str = get_between($rs2, '<img src="http://www.runescape.com/img/title2/more_news.gif" alt="More News">', '<table class="newssummary" style="width: 430px;">'); echo $str; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/ Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 Are you sure that display_errors is turned on via www.php.net/ini_set ? Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378829 Share on other sites More sharing options...
cooldude832 Posted October 26, 2007 Share Posted October 26, 2007 Don't Strip tags from the output, tags let you find stuff easier. Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378842 Share on other sites More sharing options...
phpcode Posted October 26, 2007 Author Share Posted October 26, 2007 display_errors is set in ini_set also the code works when I edited it to this:- 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; } $rs2 = strip_tags(file_get_contents("http://runescape.com/title.ws")); $str = get_between($rs2, "Latest Poll", "Vote in this poll"); echo $str; Does anyone see why the first code doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378848 Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 Kind of an oxymoron deal here. As cooldude stated the issue is with strip tags. The first post you are attempting to locate tags, but you ultimately strip them before you even try to process the page. The second post you made you are taking the text between what you want and using that, since there are no tags in the second post it works. Basically if you want to use the table or any html tags to grab data, don't strip tags from the incoming data. Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378856 Share on other sites More sharing options...
phpcode Posted October 26, 2007 Author Share Posted October 26, 2007 I've already removed the strip_tags before I created this topic and it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378861 Share on other sites More sharing options...
LemonInflux Posted October 26, 2007 Share Posted October 26, 2007 You're getting it from the RS site, right? Look for the news_lite thing. They released hiscores_lite and news_lite. If you find that, it's all just listed for you. Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378862 Share on other sites More sharing options...
sasa Posted October 26, 2007 Share Posted October 26, 2007 for me it return </div> Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378866 Share on other sites More sharing options...
phpcode Posted October 26, 2007 Author Share Posted October 26, 2007 What is the URL for news lite? I cannot find it. Quote Link to comment https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/#findComment-378870 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.