我認爲這是一個簡單的問題,但我已經完成了我所知道的但仍然無法解決的問題。我想從這個鏈接獲取輸出:使用PHP解析網頁內容
你可以粘貼在瀏覽器上,並看看它。有一些文字輸出。我試過用PHP中的一些函數,比如file_get_contents和curl。我不使用ajax或JavaScript,因爲我不熟練使用它。最後,我正在與XAMPP合作。
我認爲這是一個簡單的問題,但我已經完成了我所知道的但仍然無法解決的問題。我想從這個鏈接獲取輸出:使用PHP解析網頁內容
你可以粘貼在瀏覽器上,並看看它。有一些文字輸出。我試過用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"
謝謝總體,也許是因爲我的網絡問題 – andrefadila 2013-05-01 14:31:39
$op=file_get_contents('http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en');
echo $op;
<?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;
?>
有時特殊字符可以在這裏實現你的實際輸出是解決清潔文字例如
<!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>
讓我知道如果我能幫助你更多..
'$ content'將具有整個頁面的內容。你能告訴我如何只有文字內容到$內容? – user123 2013-08-30 13:11:27
'......我試過了一些功能......'你究竟試過了什麼?你能提供一些代碼嗎?對我來說,'file_get_contents($ url)'顯示''誰是大學的校長「。它按照提供的方式工作。 – BlitZ 2013-04-30 04:54:17
yap我無法打開流:由於目標機器在使用file_get_contents時主動拒絕,因此無法建立連接。總體來說,我嘗試像下面的所有答案。 – andrefadila 2013-04-30 05:53:11
可能是網絡問題。 – BlitZ 2013-04-30 05:54:32