0

i'm currently creating a piece of code which should simply show the text that is stored in the url via php in a variable QuoteText, like so:

post.php?PostID=7&QuoteText=This is a post

I have created the code to make a text area get this text and it should display in the text box. However for some reason I keep getting alot of whitespace characters in the text area box, although there is none in text being gotten.

Start of box |        This is a post                   | end of box

Can anybody help explain why i keep getting this problem? Thanks, i've added the code for the textarea below

<textarea name="commentMade" rows="" cols="" class="COMMENTBOX" required=required>
<?php 
if(isset($_GET['QuoteText']) != "") 
    echo $_GET['QuoteText'];
else 
    echo "COMMENTS HERE :)";
?>
</textarea>
Jono_2007
  • 1,016
  • 3
  • 12
  • 23
  • 1
    Not the problem, but... `isset($_GET['QuoteText']) != ""` doesn't make much sense. `if boolean value != ''`? – Marc B Jan 11 '12 at 15:22

5 Answers5

3

All the extra whitespace is coming from your PHP inside <textarea></textarea> tags. What you can do is this:

<?php 
if(isset($_GET['QuoteText']) != "")
    $txt = $_GET['QuoteText'];
else 
    $txt = "COMMENTS HERE :)";
?>
<textarea name="commentMade" rows="" cols="" class="COMMENTBOX" required=required><?php echo(trim($txt)); ?></textarea>
Aleks G
  • 56,435
  • 29
  • 168
  • 265
  • 1
    Aleks G could be correct as spaces could be around outside the php tags. – Riz Jan 11 '12 at 15:23
  • @bardiir: you're right, I didn't express myself clear. As dev pointed out, there could be spaces around outside the `php` tags - plus the newlines before and after the the php block itself. – Aleks G Jan 11 '12 at 15:25
  • Yep, it's probably whitespaces before and after the php tags, everything inbetween is pretty much irrelevant :) – bardiir Jan 11 '12 at 15:27
1

You could try to use trim():

if(isset($_GET['QuoteText']) != "") 
    echo trim($_GET['QuoteText']);
Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
0

The whitespace is probably in your php file at the end of the lines. Be aware that inside of <textarea> like in <pre> you can't freely set whitespaces like in other places of your html syntax, they will be displayed there.

Take a look at your HTML source that you generate and make sure there are no rogue whitespaces.

This might be related:
Why is textarea filled with mysterious white spaces?

Community
  • 1
  • 1
bardiir
  • 14,556
  • 9
  • 41
  • 66
0

Trying changing your code to ... required><?php ....

But regardless of the reasons, a trim() should let you get rid of them.

Milad Naseri
  • 4,053
  • 1
  • 27
  • 39
0

Make that single line, spaces could be there at start or rear of lines.

<textarea name="commentMade" rows="" cols="" class="COMMENTBOX" required=required><?php 
echo (isset($_GET['QuoteText']))? $_GET['QuoteText'] : "COMMENTS HERE :)";
?></textarea>
Riz
  • 9,703
  • 8
  • 38
  • 54