首页 新闻 会员 周边

在页面上输出一个php文件,<?php变成注释

0
[待解决问题]

通过以下代码在页面上输出一个php文件,结果<?php变成注释行不知道是为什么,求解答!

echo '<html><body style="background: #000; color: #fff; font-size: 100%;"><div>';
if (file_exists($path_dst)) {
if ($fd = fopen($path_dst, 'r')) {
while (!feof($fd)) {
echo fgets($fd) . "<br>";
}
}
fclose($fd);
}
echo "</div></body></html>";

 

文件内容:

<?php
   echo "test4\n";

?>

页面显示:

源码:

妞溜溜的主页 妞溜溜 | 初学一级 | 园豆:122
提问于:2015-06-02 10:07
< >
分享
所有回答(1)
0

图片看不到,效果看不到

五毛钱的饼 | 园豆:517 (小虾三级) | 2015-06-02 10:47

刚才上传有问题,现在OK了,麻烦帮忙看一下,感觉应该是浏览器解析的问题,但具体不知道原因,纠结中~

支持(0) 反对(0) 妞溜溜 | 园豆:122 (初学一级) | 2015-06-02 11:13

@妞溜溜: 我参考 http://www.laoguo.org/php_display_code.html 这个之后,OK啦

<?php

function html_entities($content){
    $content = str_replace("<", "&lt;", $content);
    $content = str_replace(">", "&gt;", $content);
    $content = str_replace(" ", "&nbsp;", $content);
    return $content;
}

$path_dst = "D:/wamp/www/testmysql.php";
echo '<html><body style="background: #000; color: #fff; font-size: 100%;"><div><pre>';
if (file_exists($path_dst)) {
    if ($fd = fopen($path_dst, 'r')) {
        while (!feof($fd)) {
            echo html_entities(fgets($fd))."<br/>";
        }
    }
    fclose($fd);
}
echo "</pre></div></body></html>";

 

支持(1) 反对(0) 五毛钱的饼 | 园豆:517 (小虾三级) | 2015-06-03 14:17

@wakasann: 问题解决了,多谢多谢O(∩_∩)O~

支持(0) 反对(0) 妞溜溜 | 园豆:122 (初学一级) | 2015-06-03 15:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册