use CURL with google translate

Discussion in 'PHP' started by linkinpark2014, Aug 12, 2009.

  1. #1
    hi all
    i have created this simple curl function to grab translated text from google translate, however after i tested it, i figured that google is blocking curl?

    here is my simple script:

    function get_content($url)  
    { 
    	$ch = curl_init();  
    	curl_setopt ($ch, CURLOPT_URL, $url);  
    	curl_setopt ($ch, CURLOPT_HEADER, 1); 
    	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');  
    	curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); //saved cookies
    	//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    	//curl_setopt($ch, CURLOPT_PROXY, 'fakeproxy.com:1080');
    	curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    	ob_start();  
    	curl_exec ($ch);  
    	curl_close ($ch);  
    	$string = ob_get_contents();  
    	ob_end_clean();  
    	return $string;      
    }
    
    echo get_content("http://translate.google.com.my/translate?u=http://php.net&sl=ar&tl=en&hl=en&ie=UTF-8");
    PHP:
    so simply the output is showing nothing..
    any ideas of how to make this work will b appreciated..
     
    linkinpark2014, Aug 12, 2009 IP
  2. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    well I got something: http://phpieceofcake.com/?45124707

    problem is i can't change their server settings so try again :)

    P.S. your php code actually isn't php code until you surround it with <?php **php code here** ?> ;)
     
    szalinski, Aug 12, 2009 IP
  3. alons

    alons Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    You dont need the above.

    I have developed a similar technology to use various translators.
    Its translates 100s of lines per second.

    Then when google realises we renew IP and continue!
     
    alons, Aug 13, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Or hell you could just pay for Google's API...
     
    kblessinggr, Aug 13, 2009 IP