I am trying to call php from within index.html. I have created index.html with some a piece of sample code. from the PHP manual

<head>
    <title>Example</title>
</head>
<body>
    <?php echo "Hi, I'm a PHP script!"; ?>
</body>

when I place this index.html file on my website, the title Example is shown in the explorer title bar, but no output is generated. I can run .php files. My questions is why want this work.

Thanks

    Your web server is not configured to parse .html files with PHP. This speeds up static html files.

    If you reconfigure your web server to parse .html files with PHP, your problem with be solved 🙂

    -Rich

      Or, change your Web Server to look for index.php for the initial page in your web site's directory. It would help keep your speed optimization on html files.

      The configuration line to add index.php in apache is "DirectoryIndex". You should see a few file names there, including index.html.

      Change your index.html to index.php and then add index.php to the "DirectoryIndex". Now when someone comes to your site, Apache should include index.php in it's files to look for. Make sure you don't have index.html in your directory.

      Reuben Stump

        Well, I'm quite new to PHP but to me it looks like you should be using ' instead of " around what you want displayed, try using <?php echo 'Hi, I'm a PHP script!'; ?>

          Well, either type of quote will work. A single quote is more efficient if you're not doing variable substitution since the PHP engine does not need to parse the string, it simply echo()s it.

          -Rich

            Or, if you don't have server setting access, create an index.html file the meta-refreshes to your index.php page.

            Anna

              Write a Reply...