0

I am trying to display the content of a file that contains both php code and html code into a textarea. I did

<textarea name='codemodifier' cols='110' rows='35' id='codemodifier' class='form-control' style='height: 75vh;'><?php echo file_get_contents("myfile.php"); ?></textarea>

However instead of it displaying only the content of the file, it displays other html codes under the textarea

enter image description here

I edited my code and did

<textarea name='codemodifier' cols='110' rows='35' id='codemodifier'
class='form-control' style='height: 75vh;'><?php echo
htmlspecialchars(file_get_contents("myfile.php")); ?></textarea>

And then nothing shows anymore in the textarea. I get the same problem when i use htmlentites instead of htmlspecialchars.

How to display content of a php and html file into a textarea ?

neuhaus
  • 3,886
  • 1
  • 10
  • 27
Man Of God
  • 774
  • 2
  • 14
  • 32
  • 1
    "I edited my code and did" - the quote is empty, you're missing something. – Elias Soares Aug 29 '17 at 13:15
  • 1
    `htmlspecialchars()` should do the trick. – neuhaus Aug 29 '17 at 13:15
  • I can't understand the language in the error but it seems to be something related to session – mrid Aug 29 '17 at 13:16
  • Check the page source and see what it looks like. I'm not 100% sure about what your actual issue is though. Is the text below the textarea suppose to be inside it? – M. Eriksson Aug 29 '17 at 13:19
  • I think this is a [duplicate](https://stackoverflow.com/questions/4705848). Does it help? – bezet Aug 29 '17 at 13:24
  • I guess the OP gave up... – M. Eriksson Aug 29 '17 at 13:47
  • @neuhaus `htmlspecialchars` and `htmlentities` did not work. When i apply it to it nothing is displayed anymore @mrid What could it possibly be because i am well logged in ? @bezet No not really. I need to edit the content in a textarea because i am creating a one file and dont want to use jquery or any library to achieve my goal @MagnusEriksson Please do you have a solution to it ? – Man Of God Aug 30 '17 at 10:57

1 Answers1

0

Those look like UTF-8 characters, try decoding them using utf_decode() before you output the contents of the file in to the textarea.

This function converts the string data from the UTF-8 encoding to ISO-8859-1. Bytes in the string which are not valid UTF-8, and UTF-8 characters which do not exist in ISO-8859-1 (that is, characters above U+00FF) are replaced with ?.

Script47
  • 14,230
  • 4
  • 45
  • 66