删除文本区域第一行的空白


Remove white space from first line of textarea

如何阻止php从文本区域第一行开始删除空白。每次我提交表格时,空格都会被删除。。。即使我将其替换为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

取消对trim的调用。

此函数返回一个字符串,字符串的开头和结尾都去掉了空白。

来自PHP文档:

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

如果你想让php保持空白,就不应该使用trim()函数。如果你对某个字符串应用trim,它会从它的开头和结尾删除空白。

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