Problem with file_get_contents

Discussion in 'PHP' started by adamjblakey, Jun 20, 2007.

  1. #1
    Hi,

    I am trying to use a site translator but i am having problems as my server does not accept the function file_get_contents.

    I need to use curl with this really but when i tried changing file_get_contents to curl_init i get an error stating Wrong parameter count

       $html = file_get_contents("http://64.233.179.104/translate_c?hl=en&ie=UTF-8&oe=UTF-8&langpair=$lang&u=" . urlencode($_GET["u"]) . "&prev=/language_tools");
    Code (markup):
    Any ideas?

    Cheers,
    Adam
     
    adamjblakey, Jun 20, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Why are you doing it this way instead of direct links to the Google translator?
    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://64.233.179.104/translate_c?hl=en&ie=UTF-8&oe=UTF-8&langpair=$lang&u=" . urlencode($_GET["u"]) . "&prev=/language_tools");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $html = curl_exec($ch);
    curl_close($ch);
    ?>
    PHP:
     
    krt, Jun 20, 2007 IP
  3. greenrob

    greenrob Peon

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Why dont you use file instaed ?

    php.net/file
     
    greenrob, Jun 20, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    If file_get_contents() is not supported/enabled, then neither is file(), it is most likely due to file handling functions being disabled for security reasons. Unless it is PHP4 < 4.3...
     
    krt, Jun 20, 2007 IP
  5. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Hi,

    Thank you for your replies, i am doing it this way as it will not display the google translator banner and looks like part of the site.

    I tried your example krt but still comes back saying:

    Warning: Wrong parameter count for curl_exec()
     
    adamjblakey, Jun 20, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    
    $html = curl_exec();
    
    PHP:
    Should be:
    
    $html = curl_exec($ch);
    
    PHP:
     
    nico_swd, Jun 20, 2007 IP
  7. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #7
    Cheers everyone, works fine now :)
     
    adamjblakey, Jun 20, 2007 IP