php - 使用 PHP 解析网页内容

标签 php file curl file-get-contents php-parser

我认为这是一个简单的问题,但我已经做了我所知道的,但仍然无法解决问题。我想从此链接获得输出:

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

您可以粘贴到浏览器上查看。有一些文本输出。我试过使用 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/

相关文章:

javascript - 通过 PHP 通过电子邮件发送 textarea HTML 代码以显示为 html

php - Joomla 数据库以及如何提取数据

mysql - 什么时候应该使用 MySQL TEXT 字段而不是文件?

json - cURL GET 查询字符串是一个 JSON

PHP:在多个请求中保持与 API 的 HTTPS 连接打开

javascript - 从数据库获取数据时html中的多个选择选项

javascript - 如何重新加载 URL 链接,使其在单击提交按钮后保持不变

c - 我在 C 语言中重命名和删除函数时遇到困难

python - 比较文件和列表以查看它们是否相同

curl - 如何访问 CouchDB 数据库中的所有文档?