每当通过form.php文件生成时,我想在div框中包含一个php文件 我在这里有一些代码已经在两行中给出了12个盒子,我想要的是每次一个盒子都在增长,并且自动将新生成的php文件包含到新生成的div框中,这里是我需要改进和修复的代码< / p>
<?php
$dir=opendir('.') or die ('Cannot open directory');
$file=readdir($dir);
for($j=1; $j < 13; $j++) :
print '<div style="float:left; width:100px">';
if(preg_match("/php$/", $file)){
include($file);
}
print '</div>';
if($j%6==0) print '<div style="clear:both;></div>';
endfor;
?>
提前感谢anyhelp
答案 0 :(得分:2)
您可以使用scandir();
这是代码:
<?php
$dir = 'folder/';
$files = scandir($dir);
$count=2;
foreach($files as $file){
$count++;
echo '<div style="float:left; width:100px">';
if(strpos($file,".php")){
include($dir.$file);
}
echo '</div>';
if($count==6){echo'<div style="clear:both;></div>';}
}
?>
如果您仍然感到困惑,请告诉我
答案 1 :(得分:1)
或更简单:
foreach(glob(dirname(__FILE__)."/*.php") as $i => $file) {
echo "<div style='float:left; width:100px'>";
include_once($file);
echo "</div>";
if($i%6==0) {
echo "<div style=\"clear:both;\"></div>";
}
);