0

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.

enter image description here

3 Answers3

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