Please help, php file function problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vilks123
    New Member
    • Oct 2006
    • 5

    Please help, php file function problem

    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&listwo rd=another&jump =another[2,pronoun]&list=anothe r[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\Programmi ng\Xampp\xampp\ htdocs\main2.ph p on line 49

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

    Any ideas?

    Thanks ,
    Andrew.
  • brid
    New Member
    • Oct 2006
    • 13

    #2
    Check allow_url_fopen :
    [PHP]
    <?
    echo "allow_url_fope n=".ini_get('al low_url_fopen') ;
    ?>
    [/PHP]

    Comment

    • vilks123
      New Member
      • Oct 2006
      • 5

      #3
      Originally posted by brid
      Check allow_url_fopen :
      [PHP]
      <?
      echo "allow_url_fope n=".ini_get('al low_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,

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

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

        Ronald :cool:

        Comment

        • vilks123
          New Member
          • Oct 2006
          • 5

          #5
          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&listwo rd=another&jump =another[1,adjective]&list=anothe r[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%3Fhd wd%3Danother%26 listword%3Danot her%26jump%3Dan other%5B1%2Cadj ective%5D%26lis t%3Danother%5B1 %2Cadjective%5D %3D42705%3Banot her%5B2%2Cprono un%5D%3D42730%3 Banother-guess%3D42749%3 Bone%20another% 3D799389%26book %3DDictionary

          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.

          Comment

          • vilks123
            New Member
            • Oct 2006
            • 5

            #6
            previous string got corrupted a little bit:

            string used in file() function:

            http://www.m-w.com/cgi-bin/dictionary%3Fhd wd%3Danother%26 listword%3Danot her%26jump%3Dan other%5B1%2Cadj ective%5D%26lis t%3Danother%5B1 %2Cadjective%5D %3D42705%3Banot her%5B2%2Cprono un%5D%3D42730%3 Banother-guess%3D42749%3 Bone%20another% 3D799389%26book %3DDi ctionary

            Comment

            • vilks123
              New Member
              • Oct 2006
              • 5

              #7
              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.

              Comment

              Working...