user1977963
user1977963

Reputation: 13

Include php file in html page

I'm working with XML and PHP to populate a web form drop down box.

I have a html page

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>

</head>

<body>
<header>
<h1>Title</h1>
</header>

    <form>
        <div id ="select xml">
            <?php include 'dropdown.php'; ?>
        </div>
    </form>
</body>

</html>

and I am hoping to include the following PHP to generate the actual box with the file names of the XML.

<?php
//echo(substr(glob("xml/*.xml")[0],4));

echo  "<p>
      <label>Select list</label><br>
      <select id = \"selectxml\">
      <option value'0'>--Please Select--</option>";

        $count = count(glob("xml/*.xml"));
        $files = glob("xml/*.xml");
        for ($i = 0; $i < $count; $i++) {
            //echo(substr($files[$i],4));
            //echo "<br>";
        $filename = (substr($files[$i],4));
        echo "<option value=$i+1>$filename</option>";   
        }     

echo  "</select><br>
      <br>
      </p>";
?>

I'm aware the PHP isnt perfect, but it works.

The issue is that the Include HTML does not work when I run the page - any ideas?

Upvotes: 1

Views: 92

Answers (3)

Alireza Fallah
Alireza Fallah

Reputation: 4607

Change the extension to .php and you will be okay .

When the page have .html extension, the web server doesn't recognize it as a PHP file, and you can't use PHP codes in it. and any PHP code, will be processed as a plain text .

I mean when you put :

<?php echo "hello" ?>

in a HMTL page, browser will show :

<?php echo "hello" ?>

But, if the page have .php extension, browser will show :

hello

Upvotes: 2

mehdi
mehdi

Reputation: 1755

it;s impossible, but with jQuery.load function you can do this :

$("#select-xml").load("dropdown.php");

Upvotes: 0

user2936213
user2936213

Reputation: 1011

Rename your html page from .html to .php

Upvotes: 0

Related Questions