Remove white space from first line of textarea

how can i prevent php to remove the whitespace from the begining of the textarea first line. Everytime i submited the form, the withespace are removed...even if i replace it for nbsp;

The code i'm using:

PHP

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

The input

   1234 5678
abcdefghif

The output

1234 5678
abcdefghif

Upvotes: 0

Views: 1398

Answers (4)

Vamsi Krishna
Vamsi Krishna

Reputation: 161

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

Upvotes: 0

Anoop
Anoop

Reputation: 173

You should not be using the trim() function if you want php to leave whitespaces as it is. If you apply trim on some string it removes whitespaces from the beginning and end of it.

Upvotes: 0

Adam Sinclair
Adam Sinclair

Reputation: 1649

From the PHP documentation :

trim — Strip whitespace (or other characters) from the beginning and end of a string

Upvotes: 0

bcmcfc
bcmcfc

Reputation: 26765

Get rid of the call to trim.

This function returns a string with whitespace stripped from the beginning and end of str.

Upvotes: 1

Related Questions