2

I think it's simple question but I've done what I know and still not work. I want get output from this link :

http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en

You can paste on the browser and look into it. There some text output. I've tried with some function in PHP like file_get_contents and curl. I'm not using ajax or JavaScript because I'm not expert with it. And the last, I'm working with XAMPP.

Punam Sapkota
  • 125
  • 1
  • 7
andrefadila
  • 647
  • 2
  • 9
  • 36
  • 1
    `... I've tried with some function ...` What exactly have you tried? Could you provide some code? For me, `file_get_contents($url)` shows `"who is the Rector of the University"`. It works as it's provided. – BlitZ Apr 30 '13 at 04:54
  • yap I get failed to open stream: No connection could be made because the target machine actively refused when using file_get_contents. Overall I've try like the all answer below. – andrefadila Apr 30 '13 at 05:53
  • Might be a network problem. – BlitZ Apr 30 '13 at 05:54
  • Yap, maybe because proxy in my office – andrefadila May 01 '13 at 14:30

4 Answers4

8
$url = 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en';

// using file_get_contents function
$content = file_get_contents($url);
echo $content;
#output# "who is the Rector of the University"

// using file function // read line by line in array
$content = file($url);
print_r($content);

#output# Array (0] => "who is the Rector of the University")

// using cURL
$ch = curl_init($url);  
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
$content = curl_exec($ch);
echo $content;
#output# "who is the Rector of the University"
Punam Sapkota
  • 125
  • 1
  • 7
0
$op=file_get_contents('http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en');

echo $op;
Suhel Meman
  • 3,702
  • 1
  • 18
  • 26
0
<?php
$url = 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en';
$op=file_get_contents($url);
echo $op;
?>
Padmanathan J
  • 4,614
  • 5
  • 37
  • 75
0

some times special character may effect to your actual output here is solve example with clean text

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php      
    $url = 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en';

    $content = file_get_contents($url);

    echo $content;
?>
</html>

let me know if i can help you more..

liyakat
  • 11,825
  • 2
  • 40
  • 46
  • `$content` will have entire content of the page. Can you please tell me how one can have only text content into $content? – user123 Aug 30 '13 at 13:11