dongxindu8753 2015-08-06 02: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 02: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部