Search code examples
phphtmltextareaform-fields

HTML / PHP - Textarea shows tabs / spaces from code


For readability reasons , I have a code that looks like this :

        <textarea cols="50" rows="5"  id="k99_brsa_settings[brsa_keep_settings_exp]"  name="k99_brsa_settings[brsa_keep_settings_exp]" />
            <?php echo $export; ?>
        </textarea>

I do not know how to represent / display tabs here , but it is actually like so :

[TAB][TAB][TAB][TAB]<textarea cols="50" rows="5" id="k99_brsa_settings[brsa_keep_settings_exp]"  name="k99_brsa_settings[brsa_keep_settings_exp]" />
[TAB][TAB][TAB][TAB][TAB]<?php echo $export; ?>
[TAB][TAB][TAB][TAB]</textarea>

or better yet with an image ( code editor ) :

Code tabs in editor

The problem is , that those tabs appear in the Output like so :

Tabs appear in textarea

and since those are DB entries, when I save , it actually CHANGES the entry (adds tabs and spaces )

I know that when I change the code to a one liner:

<textarea cols="50" rows="5"  id="k99_brsa_settings[brsa_keep_settings_exp]" name="k99_brsa_settings[brsa_keep_settings_exp]" /><?php echo $export; ?></textarea>

(image from code editor below )

Image with one liner

...there is no problem and no tabs / spaces .

Is there any way to keep the tabs for readability AND eliminating those output tabs and spaces ? Does the <textarea> TAGS always HAVE to end after the output without spaces


Solution

  • You can still keep it on multiple lines with

    <textarea ...><?php
    
    ?></textarea>
    

    Alternatively you could do:

    <?php
        echo "<textarea line1>"
            . $export
            . "</textarea>";
    ?>