EOD analyzes content

I'm trying to echo a layout file in a textbox so that the layout can be edited from the interactive interface, but the problem is that even in the heredoc in PHP, it still parses the layout. This is the code that I have to output EOD;

echo (
<<<EOD
<div class="shadowbar">
        <form method="post" action="index.php?action=acp&mode=layout">
        <fieldset>
        <legend>Advanced Layout Editor</legend>
        <div class="input-group">
        <textarea rows="8" placeholder="Layout File" name="layout" id="about" cols="100" value="$layoutFile"></textarea><br />
        </div>
        </fieldset>
        <input class="Link LButton" type="submit" value="Submit Edits" name="submit" />
    </form>
    </div>
EOD
);  

      

I originally had a variable between the text area open and close labels, but I thought that if I put it in the value area, it wouldn't give me an error. The problem is that the layout closes the textarea tags on the line that closes the textarea, and then the browser parses everything after the first closing textarea.

I was under the impression from the PHP documentation that heredoc would resolve this form and change the variable accordingly, so the question is, how would I do this so that it doesn't close the tag when it echoes as a value.

+3


source to share


1 answer


<textarea>

do not have an attribute value

. The correct syntax would be

echo <<<EOD
<textarea>$your_content_here</textarea>
EOD;

      

And note that echo

it is not a function call. Although put is (...)

not an error, it is also completely unnecessary.

Also, if you dump html into this textbox for editing, it will be parsed by the browser. for example if the html contains a form that itself has <textarea>...</textarea>

, your content will actually terminate the textbox prematurely. Make sure you run your html through htmlspecialchars()

to prevent this from happening. i.e



$text_to_edit = '<textarea>foo</textarea> Please fill in the text box';

# Output your editor form
echo <<<EOD
<textarea>$text_to_edit</textarea>
EOD;

      

will create this for HTML:

<textarea><textarea>foo</textarea>Please fill in the text box</textarea>
    a         b             c                                     d

      

You cannot nest text fields, so the B tag will be ignored, the C tag (from your "text to edit") will terminate the A tag, and the D tag will become a chattering / illegal extra end tag. Your editable text has now leaked out of the form and is no longer part of the editable text.

+3


source







All Articles