简体   繁体   English

如何将php和html文件的内容显示到textarea中?

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

I am trying to display the content of a file that contains both php code and html code into a textarea. 我正在尝试将包含php代码和html代码的文件的内容显示到文本区域中。 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 但是,它不显示仅文件内容,而是在文本区域下显示其他html代码。

在此处输入图片说明

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. 当我使用htmlentites而不是htmlspecialchars时,出现相同的问题。

How to display content of a php and html file into a textarea ? 如何将php和html文件的内容显示到textarea中?

Those look like UTF-8 characters, try decoding them using utf_decode() before you output the contents of the file in to the textarea. 这些看起来像UTF-8字符,请在将文件内容输出到textarea之前尝试使用utf_decode()对其进行解码。

This function converts the string data from the UTF-8 encoding to ISO-8859-1. 此函数将字符串数据从UTF-8编码转换为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 ?. 字符串中无效的UTF-8字节和ISO-8859-1中不存在的UTF-8字符(即U + 00FF以上的字符)将替换为?。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM