Why does my PHP appear to be commented out when I view it in the browser? <!--?php include(“header.php”); ?-->

前端 未结 5 697
感情败类
感情败类 2020-12-21 15:26

I am building a html page but want to break the header out so I dont have to keep changing all the files.

I am attempting to add a php.include file and save the pag

相关标签:
5条回答
  • 2020-12-21 15:47

    This is what I got, I took your code and saved it as index.php

    <!DOCTYPE html>
    
    <html lang="en">
    
        <head>
    
        <title>Chartego | Creating Socially Inflential People with great images and videos</title>
        <meta http-equiv="content-type" content="text/html" charset="utf-8"> 
       </head>
    <body>
    
    <?php 
       include ('header.php'); 
    ?>
    
    
      <div id="wrap-inner">
    content
    
    </div>
    

    I created this in header.php

    <?php
      echo "Hello World";
    ?>
    

    This is the output:

    Hello World
    content
    
    0 讨论(0)
  • 2020-12-21 15:53

    OK. A few things.

    1. Check that your file is actually being interpreted as PHP rather than just bog-standard HTML.
    2. Turn on all your error reporting (error_reporting = E_ALL | E_STRICT | E_WARNING in php.ini)
    3. Make sure your errors are displayed (display_errors = on in php.ini)

    Try using require rather than include as require will halt execution if it can't load the file and show an error

    0 讨论(0)
  • 2020-12-21 15:57

    when i inspect the element using chrome the php seems to be commented out

    The PHP is not passing through a PHP parser before getting to the browser, so the browser is receiving the PHP code instead of the server executing it.

    Make sure that:

    • You are loading the page over HTTP (e.g. not just double clicking the file in your file manager)
    • The server you are using supports PHP
    • The server is configured to treat the file as PHP (this is usually done by giving it a .php file extension)
    0 讨论(0)
  • 2020-12-21 16:12

    You need to check if html page can run the php code or not.
    If you are using Apache server for running html page, then the way to execute PHP on a .html page is to modify your .htaccess file. Put following code in .htaccess file:

    //for .html:
    AddType application/x-httpd-php .html
    // for .htm
    AddType application/x-httpd-php .htm
    

    For more details, read following link : http://php.about.com/od/advancedphp/p/html_php.htm

    Another possible reason can be : File is not available on the given location , so for that check the error_log.

    0 讨论(0)
  • 2020-12-21 16:13

    Your Script header.php must begin with " < ? php ' and finish with ' ? > ' and go to the php settings and uncheck 'short open tag'.

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