dongxindu8753 2015-08-06 10:01
浏览 104
已采纳

如何从php中的textarea获取文本? [关闭]

I have seen many question are here, but I can not get the answer from that. so I have type the question again here. In a same page how can I get the textarea value.

My code is like this -

<?php
    $action = $_REQUEST['action'];
    $text =$_GET['text'];
    if(!$action){
        $device=file("abc.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        $lines =implode("
",$device);
        echo "<form method='post' action='config.php'>";
        echo "<textarea name='text'  cols='40' rows='15'>$lines</textarea>";
        echo '<td> <input type="submit" name="submit" value="Submit"> </td></form>';
    }


    if($action == "submit" ){
    $ids = explode("
", str_replace("", "", $input));
        echo $ids ;
    }
?>
  • 写回答

2条回答 默认 最新

  • dongsonglian7303 2015-08-06 10:04
    关注

    You trying $_GET to get value of textarea but in form you are using post method.

    Try

    <?php
    $action = $_POST['submit'];
    $text = $_POST['text'];
    if(!$action)
    {
        $device=file("abc.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        $lines =implode("
    ",$device);
    
        echo "<form method='post' action='config.php'>";
        echo "<textarea name='text'  cols='40' rows='15'>$lines</textarea>";
        echo '<td> <input type="submit" name="submit" value="Submit"> </td></form>';
    }
    
    if($action == "submit" )
    {
        $ids = explode("
    ", str_replace("", "", $text));
        echo $ids ; 
    }
    

    FINAL UPDATE

    <?php
    if(isset($_POST['submit']))
    {   
        $text = $_POST['text'];
        $ids = explode("
    ", str_replace("", "", $text));
        echo $ids ; 
    }
    else
    {
        $device = file("abc.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        $lines = implode("
    ",$device);
    
        echo "<form method='post' action='config.php'>";
        echo "<textarea name='text' cols='40' rows='15'>$lines</textarea>";
        echo '<td><input type="submit" name="submit" value="Submit"> </td></form>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化