【问题标题】:How to display content of a php and html file into a textarea?如何将 php 和 html 文件的内容显示到 textarea 中?
【发布时间】:2017-08-29 13:13:17
【问题描述】:

我正在尝试将包含 php 代码和 html 代码的文件的内容显示到 textarea 中。我做了

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

但是它不是只显示文件的内容,而是在文本区域下显示其他 html 代码

我编辑了我的代码并做了

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

然后文本区域中不再显示任何内容。当我使用 htmlentites 而不是 htmlspecialchars 时,我遇到了同样的问题。

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

【问题讨论】:

  • “我编辑了我的代码并且做了” - 引用是空的,你错过了一些东西。
  • htmlspecialchars() 应该可以解决问题。
  • 我无法理解错误中的语言,但它似乎与会话有关
  • 检查页面源代码并查看它的外观。不过,我不是 100% 确定您的实际问题是什么。文本区域下方的文本是否应该在其中?
  • 我认为这是duplicate。有帮助吗?

标签: php html


【解决方案1】:

那些看起来像 UTF-8 字符,在将文件内容输出到 textarea 之前尝试使用 utf_decode() 对其进行解码。

此函数将字符串数据从 UTF-8 编码转换为 ISO-8859-1。字符串中不是有效 UTF-8 的字节,以及 ISO-8859-1 中不存在的 UTF-8 字符(即 U+00FF 以上的字符)被替换为 ?。

【讨论】:

  • 那行不通。我添加了 tge utf_decode,甚至将字符集设置为 ISO-8859-1,但文本仍然来自 textarea
  • 你试过&lt;?php echo htmlspecialchars(utf_decode(file_get_contents("myfile.php"))); ?&gt;
  • 能否请您提供文件内容?
猜你喜欢
  • 1970-01-01
  • 2016-06-17
  • 2011-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-04
  • 1970-01-01
  • 2011-02-15
相关资源
最近更新 更多