1

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?

1
  • 1
    be default, your server will NOT process php code in a file with .html extension. Commented Jan 24, 2014 at 13:14

3 Answers 3

2

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 
Sign up to request clarification or add additional context in comments.

Comments

0

Rename your html page from .html to .php

Comments

0

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

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

3 Comments

because the script is executed after processing the page by web server . its only working just if the dropdown.php contains html , NOT php
dropdown.php result is html elements like echo "<option value=$i+1>$filename</option>"; , i did :)
echo means nothing to web server if the file is .html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.