Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea shows extra space while retrieving from database?

Tags:

html

php

mysql

I have a simple php file that gets info from mysql database display inside textarea but when I open it from browsers it shows extra space at the beginning and end of the text inside textarea

this is how it looks (database text has no extra space)
enter image description here

this is what I did to retrieve the text

<textarea name="text" rows="9">
    <?php echo $fetchedData['founder_msg']; ?>
</textarea>

I used simple mysql_fetch_array to retrieve the value text are saved inside founder_msg field in mysql database of data type text.

like image 895
monk Avatar asked Jun 07 '12 06:06

monk


People also ask

How do I get rid of extra space in textarea?

Just put your php open tag right after the textarea close tag.. Dont use line break.. And close php exactly before (as you have done).. This will erase all the whitespaces..

How do I add a space to a textarea?

Just use non-breakable spaces: &nbsp; instead of regular spaces.


2 Answers

You're inserting a lot of white-space with your formatting. Try the following instead:

<textarea name="text" rows="9"><?php 
    echo trim( $fetchedData['founder_msg'] ); // trim, following comments
?></textarea>
like image 94
Sampson Avatar answered Oct 08 '22 18:10

Sampson


Try it like this:

<textarea name="text" rows="9"><?=trim($fetchedData['founder_msg'])?></textarea> 
like image 41
Bas Slagter Avatar answered Oct 08 '22 18:10

Bas Slagter