PHP脚本在浏览器中什么都不显示,检查元素显示<!——?php echo '祝辞


php script displays nothing in browser, inspect elements shows <!--?php echo 'Some text'; ?-->

php脚本在浏览器中不显示任何内容,检查元素显示<!--?php echo 'Text here I can't see'; ?-->

这是我的代码:

    <html>
<head>
    <title>Something</title>
</head>
<body>
    <h1>Something texttexttext</h1>
            <?php
    echo 'Text here I can't see';   
        ?>
</body>
</html>

当我在浏览器中打开这个时,我只看到-"Something texttexttext"而不是"Text here I can see"

首先,您的echo语句过早地以can't中的'结束。试一试:

    <html>
<head>
    <title>Something</title>
</head>
<body>
    <h1>Something texttexttext</h1>
            <?php
    echo "Text here I can't see";   
        ?>
</body>
</html>

这是因为你在字符串中使用了引号这是在提前结束字符串,只需用反斜杠

转义
    echo 'Text here I can''t see';   

或者只是你的引号到双引号

    echo "Text here I can't see";   

我想你是在html文件中运行这段代码而不是在php文件

如果你从你的本地服务器(即:你的计算机)或离线做这个,我相信你需要一个支持php的服务器。下载包含apache服务器的xampp就可以了。下载:http://www.apachefriends.org/en/xampp.html.

新建一个名为phpinfo.php的文件,并输入:

 <?php
   phpinfo();
  ?>

如果没有显示,您的服务器没有运行php(可能只有asp),或者您试图在浏览器中访问本地文件。与HTML文件不同,php文件需要通过服务器运行。

echo "Text here I can 't' ' see";试试

我注意到的第一件事是你在回显中使用了三个',这是行不通的。试着

<?php
    echo "Text here I can't see";   
        ?>