【问题标题】:Send raw PHP to client?将原始 PHP 发送到客户端?
【发布时间】:2014-01-16 15:23:31
【问题描述】:

是否可以将 PHP 代码发送到浏览器?

该网站目前提供 PHP 和 jQuery。

例如:

<?php echo "HELLO"; ?>

这将在客户端显示为 HELLO:

Hello

我想让客户端/浏览器接收到:

<?php echo "HELLO"; ?>

可能的结构:

index.php(主页)

edit.php(将显示 index.php 源代码的页面,包括 PHP 广告允许我对其进行编辑(并将保存服务器端))


这是一个临时的现场源代码编辑(因为我在某些地方无法访问 cPanel)。

【问题讨论】:

标签: php jquery html


【解决方案1】:

edit.php

<?php

  $cont = file_get_contents('index.php');
  echo $cont;

?>

【讨论】:

    【解决方案2】:

    不是这样的。每当口译员看到

    &lt;?php echo "HELLO"; ?&gt;
    

    为了从外部文件中获取内容,您可以使用 file_get_contents('filename.php');

     <?php echo htmlentities(file_get_contents('filename.php')); ?>
    

    【讨论】:

      【解决方案3】:

      PHP 有一个内置的语法高亮器,可以在输出 PHP 代码时为您提供帮助。

      $string = '<?php echo "abc..."; ?>';
      highlight_string($string);
      

      或者,您可以使用语法高亮输出 PHP 文件

      highlight_file('index.php');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-01
        • 2018-10-27
        • 1970-01-01
        • 2023-03-11
        相关资源
        最近更新 更多