Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:07:51+00:00 2026-06-18T00:07:51+00:00

I need to implement this PHP in my html file, this goes to a

  • 0

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.";
  }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:07:52+00:00Added an answer on June 18, 2026 at 12:07 am

    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…

    <?php
    $dir = 'xml/';
    $output;
    
    $exclude = array('somefile.php', 'somedir');
    
    // Check to see if $dir is a valid directory
    if (is_dir($dir)) {
      $contents = scandir($dir);
    
      $output .= '<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) != '.') {
      $output .= '<option>'. $file .'</option>';
      }
      }
    
      $output .= '</select>';
      }
      else {
      $output .= "The directory <strong>". $dir ."</strong> doesn't exist.";
      }
    ?>
    

    See how I’ve replaced the echo’s with $output .=? PHP is now appending those strings to the $output variable. That $variable can then be outputted anywhere on your page. I.E:

    <table>
    <tr>
    <td>
    <?php echo $output ?>
    </td>
    </tr>
    </table>
    

    You should also know about include() but I won’t explain as people have already answered accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a question about how to implement the equals method when I need
So, I need some way to implement an undirected network ( I think this
I need to implement the following: There is a table A which is supposed
If there is anyone who has used jplayer before, I need help with this
Usually when I want to create new content in a php file and implement
I have created an HTML page 'header.html'. Then I need to implement the same
I implemented a html email inside a html file. And i have a php
Need some help with this problem in implementing with XSLT, I had already implemented
I need to implement portable code, but I do not know how to deal
I need to implement an efficient excel-like app. I'm looking for a data structure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.