dpndp64206 2014-12-29 17:53
浏览 31

如何将HTML头文本文件放入PHP中的变量?

my html file look like this

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

my php file is like this

$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" );

Then i get the html response as f.txt file. I need to save the content of this file in to a variable insted of saving the file.

How could I do this? Is it possoble to do this?

  • 写回答

1条回答 默认 最新

  • douxidang9092 2014-12-29 18:02
    关注

    Untested but you can perhaps do something like:

    <?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);
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导