dongzhang1864 2014-04-27 07:21
浏览 178
已采纳

如何从html文本框中读取数据,并以与文本框相同的格式在php中打印(回显)数据?

I am beginner to PHP and here is my question. I have a text box and a 'Print' button. If 'Print' button is clicked, it should display the list of names entered in the text box. I'd written the following code, but the problem is, if I click the 'Print' button, it shows the names in a single line, instead of showing names in line by line format. Can someone help me in this. Thanks.

<!DOCTYPE html>
<html>
<head>
<title>Form Page</title>    
</head>
<body>

<form action="Files.php" method="get">
<textarea rows="15" cols="30" value="textbox" name="textbox"></textarea></br>
<input type="submit" value="Print" name="Print">
</form>

</body>
</html>

<?php
if(isset($_GET['Print'])){
    $file_print = $_GET["textbox"];
    echo $file_print;
}
?>
  • 写回答

2条回答 默认 最新

  • doulachan8217 2014-04-27 07:23
    关注

    You need to use nl2br() in PHP

    Replace echo $file_print; with echo nl2br($file_print);

    For edit..

    echo nl2br($file_print);
    file_put_contents('names.txt',$file_print,FILE_APPEND); //<-- Remove FILE_APPEND if you want to overwrite the file
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决