我在一个名为 cheeseside.php 的文件中有一些 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
}
?>
当我直接调用该文件时,它完全符合我的要求(将它找到的 php 文件列为链接。)当我尝试使用名为 currentCheese.php 的文件中的包含语句调用此文件时,我得到了绝对没有什么。我在该文件中有其他包含语句可以正常工作。我什至尝试将代码直接放在文档中,但它不起作用。我一直在搜索 php.net 手册页和堆栈溢出,以查看它是否与范围、包含 statememt 或回显有关。我只是想不通为什么我什么也得不到。