Page 1 of 1

problem with file_get_contents

Posted: Tue May 12, 2009 8:31 pm
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

Re: problem with file_get_contents

Posted: Wed May 13, 2009 3:22 am
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.

Re: problem with file_get_contents[Resolved]

Posted: Thu May 14, 2009 5:59 pm
by Mehnaz
Thanks very much for

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

Mehnaz