使用PHP解析网页内容 [英] Parse Web Page content using PHP

查看:169
本文介绍了使用PHP解析网页内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个简单的问题,但我已经做了我知道,但仍然不工作。我想从此链接获取输出:

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

您可以在浏览器上看看它。有一些文本输出。我试过一些函数在PHP像file_get_contents和curl。我不使用ajax或JavaScript,因为我不是专家。最后,我使用XAMPP。

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.

推荐答案

$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解析网页内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆