目标是让foreach循环的结果在表单页面中显示数组的内容。我已经能够显示错误消息,但是当存在多个错误消息时,不会超过一个。目前,代码返回具有多行的集合数组,但我的目的是通过各自的条件逐行生成。
的index.php
<tbody>
<?php
include './function/check.php';
foreach ($urls as $url) {
?>
<tr>
<td><a href="detail.php"> <?php print_r($url[2]); ?></a></td>
<td><a href="detail.php?pno=<?php print_r($url[1]); ?>"><?php print_r($url[1]); ?></a></td>
<td>
<?php
var_dump($output);
?>
</td>
</tr>
<?php
}
}
?>
</tbody>
check.php
<?php
include 'checkfunction.php';
if (isset($_POST['sourceDir'])) {
$sourceDir = $_POST['sourceDir'];
$urls = array();
$linecount = 1;
$output = array();
$errmsg = '';
if (is_dir($sourceDir)) {
if ($dh = opendir($sourceDir)) {
while (false !== ($filename = readdir($dh))) {
if ($filename != "." && $filename != ".." && strtolower(substr($filename, strrpos($filename, '.') + 1)) == 'php') {
$absolute_path = str_replace('\\', '/', $sourceDir) . '/';
$readfile = fopen($absolute_path . $filename, 'r');
if ($readfile) {
while (FALSE !== ($line = fgets($readfile))) {
$ary = check($line, $linecount, $filename);
if ($ary != null) {
array_push($urls, $ary);
$errmsg = array($errmsg);
$out1 = '';
foreach ($errmsg as $k => $v) {
$out1 = $v;
$output[] = $out1;
}
var_dump($output);
}
$linecount++;
}
fclose($readfile);
}
$linecount = 1;
}
}
closedir($dh);
}
}
}
?>
checkfunction.php
<?php
function check($line, $linecount, $filename) {
global $errmsg;
$urls = array($line, $linecount, $filename);
if (preg_match("/\=/", $line)) {
if (preg_match("/\\s\=\\s/i", $line) || preg_match("/\\s\==\\s/", $line) || preg_match("/\\s\===\\s/", $line)) {
} else {
$errmsg = "There should be space before and after of equal";
return $urls;
}
} elseif (strpos($line, 'if') !== false) {
if (preg_match("/\!\\\$[a-zA-z0-9]/i", $line)) {
$errmsg = "•If you want to use ifcondition, don't use !.Use false === ";
return $urls;
}
}
}
答案 0 :(得分:0)
只需在第一页开头后添加ini_set('display_errors',1);
即可。
它相当于在php.ini中启用error_reporting
//我希望那些,你正在寻找的东西..
答案 1 :(得分:0)
要做到这一点你需要使用foreach循环,试试这个:
Register
这应显示您拥有的所有错误消息