我的php脚本有什么问题

时间:2014-05-12 12:50:02

标签: php arrays foreach include

hello to stackoverflow。 (我的第一篇文章):) 我写了这个脚本

$file = glob("*.php");  // list all .php files
$findfile = array_search("index.php", $file); // search array for index.php
unset($file[$findfile]);  // remove index.php from array
sort($file, SORT_NUMERIC); // sort array 
foreach($file as $file){ include_once($file);} // include files in page

文件是1.php,2.php,3.php等

每次运行它时,文件都会包含在页面顶部。 我需要中间的文件, 我做错了什么。

这就是现在寻找的整个页面

<?php
if(isset($_POST['ta'])){
$ta = $_POST['ta'];
if($ta != "" && strlen($ta) > 1 ){
$ta = preg_replace('#[^a-z0-9 !?.,]#i', '', $ta);
$usertextinput = '<p class="important">'.$ta.'</p>';

$pho = count(glob('*.php'));
$username_file = ($pho + 1) . ".php";
$createuser = fopen($username_file, 'w');
fwrite($createuser, $usertextinput);
header("location: index.php#bottom");}}

$userpage = '<p class="important"><span>Posts\'s:</span><br />
[username] Has 1 post's To Date.</p>';?>

$file = glob("*.php");
$findfile = array_search("index.php", $file);
unset($file[$findfile]);
sort($file, SORT_NUMERIC);
foreach($file as $file){ include_once($file);}

$userpage .= '<form name="text" method="post" action="">
<textarea name="ta" placeholder=" Enter Your Comment\'s Here ">
</textarea><br />
<a name="bottom"></a>
<p class="sub"><input type="submit" value="Post To Page" /></p>';
?>

我正在建造一个邮政墙(没有数据库)

2 个答案:

答案 0 :(得分:1)

它之所以不起作用,是因为你在这里终止了php代码:

[username] Has 1 post's To Date.</p>';?>

删除?>并转义post's附近的单引号;所以代码块看起来像这样:

$userpage = '<p class="important"><span>Posts\'s:</span><br />
[username] Has 1 post\'s To Date.</p>';

$file = glob("*.php");
$findfile = array_search("index.php", $file);
unset($file[$findfile]);
sort($file, SORT_NUMERIC);
foreach($file as $file){ include_once($file);}

答案 1 :(得分:1)

放手一搏。它将在顶部输入表单,
然后Posts's: [username] Has 1 post's To Date.后跟包含的文件。

这基本上是一个展示位置问题。

<?php
if(isset($_POST['ta'])){
    $ta = $_POST['ta'];
if($ta != "" && strlen($ta) > 1 ){
    $ta = preg_replace('#[^a-z0-9 !?.,]#i', '', $ta);
    $usertextinput = '<p class="important">'.$ta.'</p>';

$pho = count(glob('*.php'));
$username_file = ($pho + 1) . ".php";
$createuser = fopen($username_file, 'w');
    fwrite($createuser, $usertextinput);
    header("location: index.php#bottom");
    }
}

$userpage = '<form name="text" method="post" action="">
<textarea name="ta" placeholder=" Enter Your Comment\'s Here ">
</textarea><br />
<a name="bottom"></a>
<p class="sub"><input type="submit" value="Post To Page" /></p>';

$userpage .= '<p class="important"><span>Posts\'s:</span><br />[username] Has 1 post\'s To Date.</p>';

echo $userpage;

$file = glob("*.php");
$findfile = array_search("index.php", $file);
    unset($file[$findfile]);
sort($file, SORT_NUMERIC);
    foreach($file as $file){
     include_once($file);
    }

?>