problem with file_get_contents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mehnaz
Forum Newbie
Posts: 20
Joined: Mon Jun 02, 2008 7:49 pm

problem with file_get_contents

Post by Mehnaz »

Hi I am using file_get_contents in this script.

Code: Select all

<?php
$urlparam = $_GET['id'];
$html = file_get_contents("http://vsearch.nlm.nih.gov/vivisimo/cgi-bin/query-meta?input-form=simple&v%3Asources=medlineplus-bundle&v%3Aproject=medlineplus&binning-state=&query=".$urlparam."&x=67&y=9");
 
$regex = '/<span class=\"url\">(.+?)<\/span>/';
 
if (!preg_match_all($regex,$html,$matches))
    return false;
 
$matches=$matches[1]; 
 
for ($i=0;$i<count($matches);$i++) {
$match=trim($matches[$i]);
 $results[]= $match;
 
 }
  
print_r(file_get_contents("http://".trim($results[0])."\"") );
  
?>
it prints the follwing output. but I want the html webpage to be parsed.

Warning: file_get_contents(http://www.nlm.nih.gov/medlineplus/cancer.html") [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\wamp\www\websearch\searchdata.php on line 18

Code: Select all

 
I am using wamp 2.0 and PHP 5.2.0. Please help
Last edited by Benjamin on Tue May 12, 2009 10:15 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: problem with file_get_contents

Post by requinix »

That "automatically parse URLs" feature can be a real bother.

Your search came up with "www.nlm.nih.gov/medlineplus/cancer.html". As far as anybody is concerned, that's a file on your server, not a webpage.
Somehow you need to check if the "http://" is present already, and if not add it yourself.
Mehnaz
Forum Newbie
Posts: 20
Joined: Mon Jun 02, 2008 7:49 pm

Re: problem with file_get_contents[Resolved]

Post by Mehnaz »

Thanks very much for

It worked by excluding double quotes in "http://

Mehnaz
Post Reply