I need to implement this PHP in my html file, this goes to a directory checks the files in there and creates a combobox with those options… now how can I can call this in a specific place in my html code.
<?php
$dir = 'xml/';
$exclude = array('somefile.php', 'somedir');
// Check to see if $dir is a valid directory
if (is_dir($dir)) {
$contents = scandir($dir);
echo '<select class="dropdown-toggle" id="combo">';
foreach($contents as $file) {
// This will exclude all filenames contained within the $exclude array
// as well as hidden files that begin with '.'
if (!in_array($file, $exclude) && substr($file, 0, 1) != '.') {
echo '<option>'. $file .'</option>';
}
}
echo '</select>';
}
else {
echo "The directory <strong>". $dir ."</strong> doesn't exist.";
}
?>
OK first of all, you don’t put PHP into HTML.
PHP is processed at the server, HTML, at the client.
Meaning by time the browser pieces the HTML together, the PHP has already been processed.
From what I can see you’d like [what you have echo’d] to be placed into a HTML element…
See how I’ve replaced the echo’s with
$output .=? PHP is now appending those strings to the$outputvariable. That $variable can then be outputted anywhere on your page. I.E:You should also know about
include()but I won’t explain as people have already answered accordingly.