Reputation: 451
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
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
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
Reputation: 1649
From the PHP documentation :
trim — Strip whitespace (or other characters) from the beginning and end of a string
Upvotes: 0