Simple PHP echo code not working

后端 未结 9 993
感情败类
感情败类 2020-12-03 17:08

Here is my html with a php script:

  
      
    Bob\'s Auto Parts
  
  

        
相关标签:
9条回答
  • 2020-12-03 17:12

    In my case (which is a very specific case) installing this missing package (Ubuntu 14.04) did the trick:

    sudo apt-get install libapache2-mod-php5
    

    for users working with php7 install the package:

    sudo apt-get install libapache2-mod-php7.0
    

    After that, just restart apache:

    sudo service apache2 restart
    

    And there you go.

    0 讨论(0)
  • 2020-12-03 17:16

    http://localhost/demo/demo.html will not work. http://localhost/demo/demo.php will work. php work on .php extension. Good Luck bro

    0 讨论(0)
  • 2020-12-03 17:25

    Make sure that you are using <?php and not <? shorthand since that may be disabled on your server. This will cause the output of "; ?> as it happened to me a few months ago in a transition to PHP5.

    I've only seen the odd output like this when the PHP parser isn't detecting it as PHP. Make sure to check that PHP is functioning as expected and that the <?php tag is being recognized.

    0 讨论(0)
  • 2020-12-03 17:25

    The file was being saved in UniCode Encoding. Opened the file in Notepad, and saved by changing the Encoding to "ANSI" and saved the file as fileName.php and type "All Files", Encoding as "ANSI".

    0 讨论(0)
  • 2020-12-03 17:27

    I had the same problem when I figured out my mistake:

    Instead of correct http://localhost/test.php I just double clicked on the file file:///C:/Users/.../htdocs/test.php.

    0 讨论(0)
  • 2020-12-03 17:31

    In order to display PHP, or run embededded PHP, you need to tell PHP to look inside the HTM & HTML files.

    You need to have a file in the root folder of the HTML directory called .htaccess, which is a simple text file, with the following line:

    #AddType application/x-httpd-php .html .htm

    This lets the PHP compiler know to compile the php when displaying the HTML page.

    0 讨论(0)
提交回复
热议问题