我认为这是一个简单的问题,但我已经做了我所知道的,但仍然无法解决问题。我想从此链接获得输出:
您可以粘贴到浏览器上查看。有一些文本输出。我试过使用 PHP 中的一些函数,如 file_get_contents 和 curl。我没有使用 ajax 或 JavaScript,因为我不是这方面的专家。最后,我正在使用 XAMPP。
最佳答案
$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"
关于php - 使用 PHP 解析网页内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16292369/