Jump to content

Recommended Posts

I have a newsite, that i like to follow, but it is constantly changing.

 

Basically I want to make a feed of sorts, but the site does not offer a feed, is there a way that I can take the source of a certain page then have a function that looks through the code for links and come out with just the links.

 

more or less i have an idea of how to do the search function, but i was wondering about the retrieving the other page, is it possible?  And if so, how?

 

thx

~D

Link to comment
https://forums.phpfreaks.com/topic/51326-opening-source-code-of-a-remote-site/
Share on other sites

<?php

function textbetweenarray($s1,$s2,$s){
  $myarray=array();
  $s1=strtolower($s1);
  $s2=strtolower($s2);
  $L1=strlen($s1);
  $L2=strlen($s2);
  $scheck=strtolower($s);

  do{
  $pos1 = strpos($scheck,$s1);
  if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
  $myarray[]=substr($s,$pos1+$L1,$pos2);
  $s=substr($s,$pos1+$L1+$pos2+$L2);
  $scheck=strtolower($s);
  }
	}
  } while (($pos1!==false)and($pos2!==false));
return $myarray;
}

$externalcontent = file_get_contents("http://www.google.co.uk");

$as = textbetweenarray("<a href=\"", "</a>", $externalcontent);
$output = array();

foreach($as as $a) {
$output[] = "<a href=\"$a</a>";
}

echo "<pre>";

foreach($output as $link) {
echo "$link\n";
}

echo "</pre>";

?>

 

That outputs each link on Google :)

K so i took part of the code you proposed and tried to change it, now it doesnt work.

 

<?php

function textbetweenarray($s1,$s2,$s){

  $myarray=array();
  $s1=strtolower($s1);
  $s2=strtolower($s2);
  $L1=strlen($s1);
  $L2=strlen($s2);
  $scheck=strtolower($s);
  $disallow = '</strong></a>';
  
  do{
  $pos = strpos($scheck,$disallow);  // this is line 21
  if($pos!==false){
$pos1 = strpos($scheck,$s1);
if($pos1!==false){
	$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
	if($pos2!==false){
		$myarray[]=substr($s,$pos1+$L1,$pos2);
		$s=substr($s,$pos1+$L1+$pos2+$L2);
		$scheck=strtolower($s);
	}
}
  }
  } while (($pos1!==false)and($pos2!==false));
return $myarray;
}

?>

 

I am trying to filter out any strings that include

</strong></a>

but i get a fatal error at line 21 , it says that it took to long to run.

 

~D

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.