0
我需要一些PHP脚本的帮助。我编写了一个脚本来分析xml并报告txt文件中的错误行。合并2个PHP脚本
代码是这样的。
<?php
function print_array($aArray)
{
echo '<pre>';
print_r($aArray);
echo '</pre>';
}
libxml_use_internal_errors(true);
$doc = new DOMDocument('1.0', 'utf-8');
$xml = file_get_contents('file.xml');
$doc->loadXML($xml);
$errors = libxml_get_errors();
print_array($errors);
$lines = file('file.xml');
$output = fopen('errors.txt', 'w');
$distinctErrors = array();
foreach ($errors as $error)
{
if (!array_key_exists($error->line, $distinctErrors))
{
$distinctErrors[$error->line] = $error->message;
fwrite($output, "Error on line #{$error->line} {$lines[$error->line-1]}\n");
}
}
fclose($output);
?>
打印阵列只能看到错误,它的唯一可选。 现在我的雇主发现了一段代码在网上
<?php
// test if the form has been submitted
if(isset($_POST['SubmitCheck'])) {
// The form has been submited
// Check the values!
$directory = $_POST['Path'];
if (! is_dir($directory)) {
exit('Invalid diretory path');
}
else
{
echo "The dir is: $directory". '<br />';
chdir($directory);
foreach (glob("*.xml") as $filename) {
echo $filename."<br />";
}
}
}
else {
// The form has not been posted
// Show the form
?>
<form id="Form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Path: <input type="text" name="Path"><br>
<input type="hidden" name="SubmitCheck" value="sent">
<input type="Submit" name="Form1_Submit" value="Path">
</form>
<?php
}
?>
,基本上发现在一个给定的目录中的所有XML,并告诉我,到2个脚本合并。 我给了输入目录,脚本应该在该目录中的所有xmls上运行,并在txt文件中给出报告。
我不知道该怎么做,我是一个PHP初学者,花了我大约2-3天的时间写出最简单的脚本。有人可以帮我解决这个问题吗?
感谢
谢谢,我终于做到了。谢谢一堆 – Mickey 2012-08-08 10:49:55