【问题标题】:Remove white space from first line of textarea从 textarea 的第一行删除空格
【发布时间】:2014-09-16 13:07:10
【问题描述】:

如何防止 php 从 textarea 第一行的开头删除空格。每次我提交表单时,withespace 都会被删除...即使我将其替换为 nbsp;

我正在使用的代码:

PHP

if(isset($_POST['btn_cel'])){ 
    $text = trim($_POST['cel']);
    $text = explode("\n", $text);
    foreach($texto as $line){
        echo str_replace(' ',' ',$line);
    } 
}

输入

   1234 5678
abcdefghif

输出

1234 5678
abcdefghif

【问题讨论】:

  • 删除 $text = trim($_POST['cel']);这一行
  • 发布您的 html 文本区域

标签: php html submit whitespace


【解决方案1】:

摆脱对trim的调用。

这个函数返回一个字符串,从 str 的开头和结尾去掉空格。

【讨论】:

    【解决方案2】:

    来自 PHP 文档:

    trim — 从字符串的开头和结尾去除空格(或其他字符)

    【讨论】:

      【解决方案3】:

      如果您希望 php 保留空白,则不应使用 trim() 函数。如果你对某个字符串应用修剪,它会从它的开头和结尾删除空格。

      【讨论】:

        【解决方案4】:
        if(isset($_POST['btn_cel'])){ 
            $text = trim($_POST['cel']);
            $text = explode("\n", $text);
            foreach($texto as $line){
                echo trim(str_replace(' ',' ',$line));
            } 
        }
        

        【讨论】:

        • 它总是有助于解释如何这回答了这个问题。此答案被自动标记为低质量,因为它是仅代码答案。
        猜你喜欢
        • 2015-11-09
        • 2023-03-18
        • 1970-01-01
        • 2011-05-12
        • 1970-01-01
        • 2016-12-06
        • 2013-09-23
        • 2018-01-09
        • 1970-01-01
        相关资源
        最近更新 更多