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

  • Home
  • SEARCH
  • 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 8488205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:28:07+00:00 2026-06-10T21:28:07+00:00

Problem I am trying to display a random page from a file called ../health/

  • 0

Problem

I am trying to display a random page from a file called ../health/
In this file there is a index.php file and 118 other files named php files.
I would like to randomly display a file from the health folder but i would like it to exclude the index.php file.

This following code includes the index.php file sometimes.
I have also tried altering the $exclude line to show ../health/index.php but still no luck.

<?php
$exclude = array("index.php"); // can add more here later
$answer = array_diff(glob("../health/*.php"),$exclude);
$whatanswer = $answer[mt_rand(0, count($answer) -1)];
include ($whatanswer);
?

Another code i have tried is the following

<?php
$exclude = array("../health/index.php"); // can add more here later
$health = glob("../health/*.php");
foreach ($health as $key => $filename) {
foreach ($exclude as $x) {
if (strstr($filename, $x)) {
unset($whathealth[$key]);
}
}
}
$whathealth = $health[mt_rand(0, count($health) -1)];
include ($whathealth);
?>

This code also includes the index.php file but rather than showing the page it displays the page as an error.

  • 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-10T21:28:09+00:00Added an answer on June 10, 2026 at 9:28 pm

    The first thing that came to mind is array_filter(), actually it was preg_grep(), but that doesn’t matter:

    $health = array_filter(glob("../health/*.php"), function($v) {
        return false === strpos($v, 'index.php');
    });
    

    With preg_grep() using PREG_GREP_INVERT to exclude the pattern:

    $health = preg_grep('/index\.php$/', glob('../health/*.php'), PREG_GREP_INVERT);
    

    It avoids having to use a callback though practically it will likely have the same performance

    Update

    The full code that should work for your particular case:

    $health = preg_grep('/index\.php$/', glob('../health/*.php'), PREG_GREP_INVERT);
    $whathealth = $health[mt_rand(0, count($health) -1)];
    include ($whathealth);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to test for something's visibility with $(this).css('display')==none; The problem is, it works
I am trying to display random banner each time the user refresh the page.
Can any 1 help me to get this problem done I'm trying to display
I'm trying to display the html inside of a php file i have. I'm
i am trying to build up a single.php page. this page is used to
This is a very beginner problem. I'm trying to display an image taken with
I have a problem when trying to display a MsExcel file in a JFrame
Problem: The data I'm trying to display is essentially a collection of collections of
I'm trying to display a text using the code below. The problem is that
I'm trying to display a UILabel on top of a UINavigationController. The problem is

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.