0

Normally when we use:

<textarea><?php echo 'ok'; ?></textarea>

We get <?php echo 'ok'; ?> displayed inside the textarea. But on my website I get the ok inside the textarea. So the php code gets executed instead the php code is being showed.

Anybody knows how this can happen? To be clear, I don't want it. I want the code to be displayed.

1 Answer 1

1

If you're running a .php file on a PHP-enabled web server... Use the HTML entities for the text you want (specifically the < and >, though potentially more):

<textarea>&lt;?php echo 'ok'; ?&gt;</textarea>

Or you can treat it as a string server-side and HTML-encode it with PHP:

<textarea><?php echo htmlentities("<?php echo 'ok'; ?>"); ?></textarea>

Alternatively, if you don't want to use PHP at all, then simply don't use it. Serve an .html file and/or disable PHP on the server:

<textarea><?php echo 'ok'; ?></textarea>

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply but it's not gonna solve my issue. I want to achieve/restore the normal behavior.
@Kip: I honestly wasn't expecting the <textarea> to treat the < and the > as HTML entities, but that seems to work too. I've updated the answer. I would still highly recommend HTML-encoding any output. Especially if that output is in any way user-editable. Otherwise you could expose users to security risks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.