繁体   English   中英

使用php编辑文本文件中的一组行

[英]edit group of line in the text file using php

我有一个文本文件,在顶部和底部都有公司详细信息。 中间有这样的所有员工详细信息

Company name: ABC Group of company
Company Location: AYZ
Company Address: XYS,YTS,123
Company found: 2013
Company website: abc.com
Company email: email@abc.com

Employee number: 001
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager

Employee number: 003
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager  

Employee number: 004
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager  

Employee number: 011
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager  

Employee number: 022
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager

Employee number: 044
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager

Employee number: 009
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager  

Employee number: 031
Employee name: ABC
Employee phone number: 123456789
Employee address: XYX, HHH,123
employee date of birth:xxxx
employee email:xxxx
employee joined date:xxxx
employee position: manager

company chairman name:jjjj
company type of business:ffffff

我需要使用以下功能创建一个php页面

list all employee details
edit a employee details
delete a employee details
add new employee details

如果此信息存储在数据库中,我可以轻松地做到这一点。 我认为通过逐行阅读,我可以轻松列出所有员工详细信息。

1) is there any other best way to do listing?
2) how can i edit/delete/add employee details?

你能帮上忙吗?

谢谢

将数据读入数据库是有趣的部分,因为如果您犯了错误,则可以截断表。

但是执行CRUD(创建读取更新删除)并不是一件有趣的事情,许多基本乏味的工作没有人会为您提供代码或为您完成解决方案。 如果您想成为一名优秀的程序员,则需要一直学习和自学!

我敢肯定那里有更好的资源,但是w3schools的速成课程肯定会助您一臂之力。

1. PHP: http //www.w3schools.com/php/default.asp

2. MySQL: http //www.w3schools.com/php/php_mysql_intro.asp

3. PHP mySQLi分机: http : //www.w3schools.com/php/php_ref_mysqli.asp

4. JavaScript,jQuery和AngularJShttp : //www.w3schools.com/js/default.asp

好的,继续一些免费的代码,将数据读入数据库:

http://phpfiddle.org/main/code/ix3s-bmzz

$lines = file("employeedata.txt");

$final_company = array();
$final_employees = array();
$employee = array();
foreach($lines as $line)
{
    $line = str_replace("\n","",$line); // Clear end of line character

    if ($line != "") {  // Check for blank line (indicator of next record)
        $arr = explode(":",$line);
        $fields = explode(" ",$arr[0]);
        $vals = $arr[1];
        switch(strtolower($fields[0])) {
            case "company" : $final_company[$fields[1]] = $vals;
            break;
            case "employee" : $employee[$fields[1]] = $vals;
            break;
        }
    } else {        
        if (!empty($employee)) array_push($final_employees, $employee);
        $employee = array(); // Clear array for next employee
    }
}
if (!empty($employee)) array_push($final_employees, $employee); //Catch last entry

// Enter your DB INSERT statement here, following is a dump of the arrays

echo "<pre> <b>COMPANY DATA:</b><br/>";
print_r($final_company); 
echo "<b>EMPLOYEE DATA:</b><br/>";
print_r($final_employees);
echo "</pre>";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM