Jump to content

Recommended Posts

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;
?>

Link to comment
https://forums.phpfreaks.com/topic/74921-grabbing-certain-part-of-websites-source/
Share on other sites

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?

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.

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.