Dreg Posted May 17, 2007 Share Posted May 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/51856-web-content-fetching/ Share on other sites More sharing options...
dj-kenpo Posted May 17, 2007 Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51856-web-content-fetching/#findComment-255564 Share on other sites More sharing options...
dj-kenpo Posted May 17, 2007 Share Posted May 17, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/51856-web-content-fetching/#findComment-255581 Share on other sites More sharing options...
chigley Posted May 17, 2007 Share Posted May 17, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/51856-web-content-fetching/#findComment-255604 Share on other sites More sharing options...
Dreg Posted May 17, 2007 Author Share Posted May 17, 2007 Thanks guys, I am checking out curl right now and it seems to be a good start and I think it could work out to be a solution. I will post back if I get it working a little more. Quote Link to comment https://forums.phpfreaks.com/topic/51856-web-content-fetching/#findComment-255640 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.