按空间序列读取的ZIP文件内容

时间:2015-12-12 05:19:15

标签: php

我在php工作,我想从zip文件中读取一些文本文件,如:

while($zip_entry = zip_read($zip)) {    
    $TableName = strstr(zip_entry_name($zip_entry), '.', true);
}

它按此顺序给出了表名,如:

1 : BPBrick
2 : BPCust
3 : BPProd
6 : BPStock <---- Notice these lines
5 : BPTran  <---- 
4 : BPValue

但是我想用自己的序列来阅读它,下面是所需的序列:

1 : BPBrick
2 : BPCust
3 : BPProd
6 : BPTran <------ These lines reversed
5 : BPStock <-----
4 : BPValue

如何可行,我试图将数组放入:

while($zip_entry = zip_read($zip)) {
    incoming_array[] = $zip_entry;
}

然后从此数组中获取。问题是,

while($zip_entry = zip_read($zip)) {    
}
  `
上面的数组后

不起作用。我的问题是:

如何在阵列中存储文本文件并在此之后调用读取功能?

1 个答案:

答案 0 :(得分:0)

好的,这段代码片段可以帮助您使用该逻辑对数组进行排序

$name = '';
$nameErr = '';
function test_input($data){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    if (empty($_POST['name'])){
        $nameErr = 'Name is Required';
    }else {
        $name = test_input($_POST['name']);
        if (!preg_match("/^[a-zA-Z ]*$/",$name)){
            $nameErr = 'Only letters and white spcaes are allowed';
        }else{
            $name = $_POST['name'];
        }
    }
    //if (!empty($nameErr)){
    $errors = array ($nameErr);
    if ($errors != ''){
            //var_dump ($nameErr);
             var_dump ($errors);
?>
<h2>FeedBack Form</h2>
<span class="error">* Required Fields</span>
<br /><br />
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
Name:<input type="text" name="name" value="<?php echo $name ?>" />
<span class="error">*<?php echo $nameErr ?></span>
<br /><br />
<input type="submit" name="submit" value="submit" />
</form> 
<?php
    }else {
        echo $name;
    }
}else {
?>
<h2>FeedBack Form</h2>
<span class="error">* Required Fields</span>
<br /><br />
<form method="post" action="<?php echo htmlspecialchars($_SERVER ['PHP_SELF']); ?>">
Name:<input type="text" name="name" value="" />
<span class="error">*</span>
<br /><br />
<input type="submit" name="submit" value="submit" />
</form>
<?php   
   }
?>
</body>
</html>