I have some data being displayed to edit in a form. In the textarea fields, there is a bunch of spaces being added after the data.

This data is being pulled from a database.

Here is the code:

<tr>
    <td width="50%"><div align="right">Description: </div></td>
    <td width="50"><div align="left"><textarea name="edit_release_description" id="edit_release_description" cols="45" rows="5"
    <?php
    if(!empty($release_no_set)){
    echo '>';
    echo trim($row['description'], ' ');
    } else {
    echo 'disabled="true"';
    echo '>';
    }
    ?>
    </textarea></div></td>
  </tr>

and

<tr>
    <td width="50%"><div align="right">Notes:</div></td>
    <td width="50"><div align="left"><textarea name="edit_release_notes" id="edit_release_notes" cols="45" rows="5"
    <?php
    if(!empty($release_no_set)){
      echo '>';
      echo $row['notes'];
    } else {
        echo 'disabled="true"';
        echo '>';
    }
    ?>
    </textarea></div></td>
  </tr>

It is only textarea fields that have the whitespace.

Also...How can I convert returns in a text area into html line breaks? I suppose I can use str_replace() somehow?

    running trim should take out all whitespace from before and after the text.
    try just using trim($value) instead of trim($value, ' ')

      No dice, it is still showing whitespace. I think it may have something to do with how it's being put into the test area, but I can't nail it down.

        try viewing the source and see if there is anything unexpected

          In the source it shows white space after the data in between the <textarea> and </textarea> tags. I would paste it here, but it will be trimmed off making me look crazy 🙂.

          I am positive that the whitespace is not comming from the database too.

            i've had problems in the past with textareas adding extra whitespace when the closing tag doesn't follow the text immediately.

            like this:

            <textarea>text here
            </textarea>
            

            solved by making sure it is closed right after like this:

            <textarea>text here</textarea>
            

              I love you. Haha. I moved the closing tag up one line and it worked out perfectly.

              I edited my first post with this "Also...How can I convert returns in a text area into html line breaks? I suppose I can use str_replace() somehow?" right after you made your first post I think. Any input on this before I mark this as resolved?

                I used str_replace(Chr(13), '<br />', $data) and it worked like a charm!

                Thanks!

                  Write a Reply...