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 9142315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:45:39+00:00 2026-06-17T09:45:39+00:00

I have some php in a file on its own called cheeseside.php <?php foreach

  • 0

I have some php in a file on its own called cheeseside.php

<?php
foreach (glob("./Cheese_of_Week/*.php") as $fileName) {  //set files in specified directory as $fileName
   $fileContents = file_get_contents($fileName); //retrieve the contents of the php file in string format
   $findme   = 'id="cheeseName'; //finds where the cheese name starts in the file
   $findme2 = '</h2>'; //find the end of the cheese name
   $pos = strpos($fileContents, $findme); //finds the offset starting position 
   $pos2 = strpos($fileContents, $findme2, $pos); //finds the ending position of the name
   $cheesePos=$pos+strlen($findme)+2; //finds the real starting position by cominsating for the search term and 2 characters of the html tag that I didn't include in the search term
   $cheeseName = substr($fileContents, $cheesePos, $pos2-$cheesePos); //Isolates the cheese name from the     $fileContents string
   if ($fileName != "./Cheese_of_Week/currentCheese.php")  //avoids repeating the current cheese which is one of the php files that will be pulled
     echo "<a href=\"$fileName\">".$cheeseName."</a>"."<br/>"; //makes a link to the the php file    
} 
?>

When I call the file directly, it does exactly what I want it to do (list the php files it finds as links.) When I try to call this file with an include statement from a the file called currentCheese.php, I get absolutely nothing. I have other include statements in that file that work fine. I even tried putting the code directly in the document and it won’t work. I have been searching through the php.net manual pages and stack overflow to see if it has something to do with the scope, or the include statememt, or the echo. I just can’t figure out why I’m getting nothing.

  • 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-17T09:45:40+00:00Added an answer on June 17, 2026 at 9:45 am

    Keep in mind that glob("./Cheese_of_Week/*.php") is relative to your entry point, in your case currentCheese.php

    To make the path always relate to the location of cheeseside.php use:

    glob(__DIR__ . "/Cheese_of_Week/*.php");
    

    About __DIR__

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

Sidebar

Related Questions

Some setup background first: I have a cronjob which runs a PHP file called
I have some issues with a PHP file that is not working properly. The
I have some setup code in my functions.php file that sets permalinks and adds
I have a php file which has some variables like $name1, $name2... How can
For some reasons I have a 663.php file in every folder and subfolders of
So I have a php file that retrieves some variables with the $_GET method
I have a settings.php file with parametric variables and a functions.php with well, some
i have an form which will send some data to an php file ,
I have an .htaccess file with following content: AddHandler x-httpd-php5 .php For some reason,
I have an external file with some vars to require in my php class

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.