Jump to content

Web Content Fetching


Dreg

Recommended Posts

Hi guys!

 

I have read the forum rules and checked out the sites listed as having possable answers to my problem but no luck. Here is my problem at the moment.

 

I have a php script that allows me to place information into an image, All in the hope of creating a site that grab content from another site and display it in the image in the form of a forum signature.

 

I have checked out a few web content fetching scripts but they dont seem to give me quite that I need. So basicley this is what I am hopeing to acheve.

 

1) A script that can fetch certain words from another site e.g. "Username: Dreg" I would like to fetch the word "Dreg"

2) I would like to be able to get the username and turn it into the value $user

3) I would then like to be able to use that value anywhere on my site.

 

If this is not possable then thanks for your time!

 

Thanks for reading and hopefuly on of you nice people will be willing to give me a push in the right direction.

Link to comment
Share on other sites

well, curl library is a good start as someone just got me using it on my second last question to this forum. now as to how you will read the specific parts eg username, not sure. but curl will grab the body of text FROM the webpage, then you just need to filter.

 

part 1 anyways

Link to comment
Share on other sites

possible part 2.

 

I just answered my own question like a dumbass on my own thread. now I'm back to yours.

 

check out string parse.

 

depending on how the username etc is written on the page you're accessing (you haven't given any details for anyone to go on here) this might work for extracting the data

 

http://ca.php.net/manual/en/function.parse-str.php

 

<?php

$str = "first=value&arr[]=foo+bar&arr[]=baz";

parse_str($str);

echo $first;  // value

echo $arr[0]; // foo bar

echo $arr[1]; // baz

 

parse_str($str, $output);

echo $output['first'];  // value

echo $output['arr'][0]; // foo bar

echo $output['arr'][1]; // baz

 

?>

Link to comment
Share on other sites

file_get_contents()

cURL

preg_match()

 

Read up on those :) Use file_get_contents() where possible, but if you need to login to fetch the data then go with cURL. I'm not a fan of using preg_match(), but I find this function useful:

 

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

$string = "iamaphpfreak";
$array = textbetweenarray("iama", "freak", $string);
echo $array[0]; // Echo: php

?>

Link to comment
Share on other sites

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.