Parse Web Page content using PHP

2019-07-23 13:43发布

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.

4条回答
唯我独甜
2楼-- · 2019-07-23 14:08
$op=file_get_contents('http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en');

echo $op;
查看更多
贪生不怕死
3楼-- · 2019-07-23 14:10
<?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;
?>
查看更多
虎瘦雄心在
4楼-- · 2019-07-23 14:19

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..

查看更多
萌系小妹纸
5楼-- · 2019-07-23 14:22
$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"
查看更多
登录 后发表回答