Home > Enterprise >  Php code gets executed instead of displayed in textarea, how to solve?
Php code gets executed instead of displayed in textarea, how to solve?

Time:04-17

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.

CodePudding user response:

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>

  • Related