2014-12-29 68 views
0

我的HTML文件看起來像這樣如何將HTML標頭文本文件放入PHP中的變量中?

<form action="cnvrt.php" method="POST" > 
     Enter your text here - <input type="text" id="in" name="in"> <br> 
     <input type="submit" value="submit" > 
    </form> 

我的PHP文件是這樣的

$in = $_POST['in']; 
$url = "https://translate.google.com/translate_a/single?client=t&sl=auto&tl=si&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&prev=btn&rom=1&ssel=0&tsel=0&tk=517882|775443&q=$in"; 
header("Location: $url"); 

然後我得到的HTML響應,f.txt文件。我需要將此文件的內容保存到一個保存文件的變量中。

我該怎麼做?這樣做是否可行?

+1

哪來你的代碼的其餘部分,上面會不會寫入文件 –

+2

http://php.net/manual/en/function.file -get-contents.php – hungerstar

+0

mybad,google向你發送文件:/ –

回答

0

未經測試,但你也許可以這樣做:

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['in'])) { 

    $in = $_POST['in']; 

    $url = "https://translate.google.com/translate_a/single?client=t&sl=auto&tl=si&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&prev=btn&rom=1&ssel=0&tsel=0&tk=517882|775443&q=".$in; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

    $your_var = curl_exec($ch); 
    curl_close($ch); 
} 
?> 
相關問題