I have displayed some text data in <textarea>
tag after getting the data form controller. But the text have extra white spaces at the beginning.
Asked
Active
Viewed 965 times
0

yasir_tetralogicx
- 43
- 5
-
1Any code to show? – GetSet Sep 15 '20 at 11:03
-
1`ltrim()` removes whitespaces from the left – Michel Sep 15 '20 at 11:04
-
If that is a browser only one whitespace character would display. Is a WYSIWYG being used and perhaps you have ` `s or `&$160;`s? Please show what you've tried and what the actual string starts off with. – user3783243 Sep 15 '20 at 11:26
3 Answers
1
For this Case PHP has some built-in functions. At the end of the answer, i will provide the direct links to the docs.
In your case you should use the trim() Method. This simply strips the whitespaces from the beginning and the end of the string.
<?php
$textarea = " Lorem ipsum dolor ";
$trimmed_textarea = trim($textarea); //this returns the $textarea string without whitespaces
echo $trimmed_textarea;
?>
If you need further instructions, you can look into the docs of the trim function. trim()

Yannick
- 177
- 2
- 13
0
//in controller
$texts = "this is very very long text"; //you might retrieve from database
//final use
trim($texts);

ppegu
- 362
- 2
- 9
- 22
0
Updating this $message ?? ''
to this $message
in the .html file fixed the issue for me

MT_Shikomba
- 129
- 1
- 6