Connecting Tech Pros Worldwide Forums | Help | Site Map

Please help, php file function problem

Newbie
 
Join Date: Oct 2006
Posts: 5
#1: Oct 20 '06
Hi,
I am using PHP 5.0 file() function to get content of a web page

here is the string i use with the file function:

$str="http://www.m-w.com/cgi-bin/dictionary?hdwd=another&listword=another&jump=anot her[2,pronoun]&list=another[1,adjective]=42705;another[2,pronoun]=42730;another-guess=42749;one another=799389&book=Dictionary";

file($str)

I get an error:
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\Program Files\Programming\Xampp\xampp\htdocs\main2.php on line 49

However, if i put that string directly into browser everything seems to work fine.

Any ideas?

Thanks ,
Andrew.

Newbie
 
Join Date: Oct 2006
Location: Beside my computer :)
Posts: 13
#2: Oct 20 '06

re: Please help, php file function problem


Check allow_url_fopen:
[PHP]
<?
echo "allow_url_fopen=".ini_get('allow_url_fopen');
?>
[/PHP]
Newbie
 
Join Date: Oct 2006
Posts: 5
#3: Oct 20 '06

re: Please help, php file function problem


Quote:

Originally Posted by brid

Check allow_url_fopen:
[PHP]
<?
echo "allow_url_fopen=".ini_get('allow_url_fopen');
?>
[/PHP]


Gives an answer of 1 , Enabled i guess

Btw, i can open a typical url like www.yahoo.com or www.m-w.com using file function no problem , it's the particular string that gives me problem for some reason.

thanks anyway,
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Oct 20 '06

re: Please help, php file function problem


You are using special chars, so have you used the urlencode() function to encode the parameters?

Ronald :cool:
Newbie
 
Join Date: Oct 2006
Posts: 5
#5: Oct 20 '06

re: Please help, php file function problem


Thanks,

urlencode or rawurlencode does solve the problem with error code 400. However , the newly formated string cannot be found. Here is what i get :

The requested URL /cgi-bin/dictionary?hdwd=another&listword=another&jump=anot her[1,adjective]&list=another[1,adjective]=42705;another[2,pronoun]=42730;another-guess=42749;one another=799389&book=Dictionary

was not found on this server.

Apache/1.3.27 Server at www.merriam-webster.com Port 80

when the string in the file() function was

http://www.m-w.com/cgi-bin/dictionary%3Fhdwd%3Danother%26listword%3Danother%2 6jump%3Danother%5B1%2Cadjective%5D%26list%3Danothe r%5B1%2Cadjective%5D%3D42705%3Banother%5B2%2Cprono un%5D%3D42730%3Banother-guess%3D42749%3Bone%20another%3D799389%26book%3DDi ctionary

Interestingly enough if i put this string into a browser i get the same result that url is not found.
Yet when i put the string without special formatting in the browser,
the one between The requested URL and was not found on this server, everything seems to work fine.
Newbie
 
Join Date: Oct 2006
Posts: 5
#6: Oct 20 '06

re: Please help, php file function problem


previous string got corrupted a little bit:

string used in file() function:

http://www.m-w.com/cgi-bin/dictionary%3Fhdwd%3Danother%26listword%3Danother%2 6jump%3Danother%5B1%2Cadjective%5D%26list%3Danothe r%5B1%2Cadjective%5D%3D42705%3Banother%5B2%2Cprono un%5D%3D42730%3Banother-guess%3D42749%3Bone%20another%3D799389%26book%3DDi ctionary
Newbie
 
Join Date: Oct 2006
Posts: 5
#7: Oct 20 '06

re: Please help, php file function problem


I guess every string will get corrupted if i am going to submit it in this window. The point is there is no spaces anywhere in the string as they have been replaced by %20 character.
Reply