我正在尝试解决 CSV 报告的问题。我正在尝试根据用户选择的报告中的字符串查找特定信息。它是包含有关许多不同事件和日期的信息的报告(一个事件可能有多个日期,因此每个日期都会重复,导致事件名称多次出现)
用户选择多个表演(特定事件/日期组合),然后使用每个表演的编号将这些表演添加到数组中eventId
:
例如
$eventArray = array(232 => 'event one', 21 => 'event four', 443 = 'event one');
每个存在eventid => eventName
(可以有重复的事件名称,因为它们在系统中有不同的日期)。
我正在阅读报告,内容如下:
$file_handle = fopen("$reportUrl", "r");
while(!feof($file_handle))
{
$line_of_text = fgetcsv($file_handle, 20000);
include('logic/finance_logic.php');
}
fclose($file_handle);
因此,对于 CSV 中的每一行,它都在运行finance_logic.php
文件中的代码。我遇到困难的部分如下:
// CHECK TO SEE IF THE FIRST LINE IS AN EVENT IN THE ARRAY (NOTE, THERE CAN BE DOUPLICATES)
if(in_array(trim(substr($line_of_text[0],6)), $eventArray))
{
$f = 1;
// get event name
$eventName = trim(substr($line_of_text[0],6));
// date of event
$eventDateArray = getEventDateArray($eventName);
}
if(isset($f))
{
$dateSearch = checkDateInArray($line_of_text[0], $eventDateArray);
if($f == 1 && $dateSearch[0] == 'found')
{
$eventId = $dateSearch[1];
$f = 2;
}
checkDateInArray
功能如下:
function checkDateInArray($date, $array)
{
if(is_array($array))
{
foreach($array as $key => $d)
{
if (strpos($date, $d) !== false)
{
// return array with first value 'found' and second being the key which is the event id
return array('found', $key);
}
}
}
}
注意:时间并不总是以格林威治标准时间结尾,因为它取决于位置,因此在比较日期时也需要忽略这一点。
所有这些都会导致对某些事情的混乱修复,我相信另一种方式要简单得多。我正在考虑的一种方法是创建的事件数组是,eventId => eventName
但与数据库中的和eventId
链接。有没有办法我可以创建一个which was然后检查它是否在这些中。我不知道该怎么做。此外,CSV 的布局方式示例如下:eventName
eventDate
eventArray
eventId => array('eventName', 'eventDate')
"Event: Event One"
""
"Performance Date: 15 Feb 2013 07:30 PM GMT"
""
"Venue: Theatre"
""
"Category: English Comedy"
"Discount","A",
"GENERAL ADMISSION",35.00,
"RESERVED",0.00,
"COMPLIMENTARY",0.00,
"SPECIAL",0.00,
"Holds","A","Face Value Amt",
"H: House Seats",16,16,
"Face Value Amt",,,
"--",,,
"Capacity",371,371,
""
"INT"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"GENERAL ADMISSION",119,4165.00,119,4165.00,
"Totals*",119,4165.00,119,4165.00,
""
"PBO"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"*SPECIAL",10,220.00,10,220.00,
"COMPLIMENTARY",4,0.00,4,0.00,
"GENERAL ADMISSION",22,770.00,22,770.00,
"RESERVED",0,0.00,0,0.00,
"Totals*",36,990.00,36,990.00,
""
"PHO"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"*GENERAL ADMISSION",0,0.00,0,0.00,
"*SPECIAL",42,940.00,42,940.00,
"COMPLIMENTARY",10,0.00,10,0.00,
"GENERAL ADMISSION",68,2380.00,68,2380.00,
"RESERVED",0,0.00,0,0.00,
"Totals*",120,3320.00,120,3320.00,
""
"PERFORMANCE TOTALS"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"*GENERAL ADMISSION",0,0.00,0,0.00,
"*SPECIAL",52,1160.00,52,1160.00,
"COMPLIMENTARY",14,0.00,14,0.00,
"GENERAL ADMISSION",209,7315.00,209,7315.00,
"RESERVED",0,0.00,0,0.00,
"Totals*",275,8475.00,275,8475.00,
""
"Abbreviated Performance Totals"
"Event","Performance Date","Discount","Tickets","Face Value Amt",
Event One,15 Feb 2013 07:30 PM GMT,*GENERAL ADMISSION,0,0.00,
Event One,15 Feb 2013 07:30 PM GMT,*SPECIAL,52,1160.00,
Event One,15 Feb 2013 07:30 PM GMT,COMPLIMENTARY,14,0.00,
Event One,15 Feb 2013 07:30 PM GMT,GENERAL ADMISSION,209,7315.00,
Event One,15 Feb 2013 07:30 PM GMT,RESERVED,0,0.00,
,,,275,8475.00,
""
"Event: Event One"
""
"Performance Date: 16 Feb 2013 07:30 PM GMT+04:00"
""
"Venue: Theatre"
""
"Category: English Comedy"
"Discount","A",
"GENERAL ADMISSION",35.00,
"RESERVED",0.00,
"COMPLIMENTARY",0.00,
"SPECIAL",0.00,
""
"INT"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"GENERAL ADMISSION",203,7105.00,203,7105.00,
"Totals*",203,7105.00,203,7105.00,
""
"PBO"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"GENERAL ADMISSION",36,1260.00,36,1260.00,
"RESERVED",0,0.00,0,0.00,
"Totals*",36,1260.00,36,1260.00,
""
"PHO"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"COMPLIMENTARY",15,0.00,15,0.00,
"GENERAL ADMISSION",99,3465.00,99,3465.00,
"RESERVED",-9,0.00,-9,0.00,
"Totals*",105,3465.00,105,3465.00,
""
"PERFORMANCE TOTALS"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"COMPLIMENTARY",15,0.00,15,0.00,
"GENERAL ADMISSION",338,11830.00,338,11830.00,
"RESERVED",-9,0.00,-9,0.00,
"Totals*",344,11830.00,344,11830.00,
""
"Abbreviated Performance Totals"
"Event","Performance Date","Discount","Tickets","Face Value Amt",
Event One,16 Feb 2013 07:30 PM GMT,COMPLIMENTARY,15,0.00,
Event One,16 Feb 2013 07:30 PM GMT,GENERAL ADMISSION,338,11830.00,
Event One,16 Feb 2013 07:30 PM GMT,RESERVED,-9,0.00,
,,,344,11830.00,
""
"Event: Event Four"
""
"Performance Date: 18 Feb 2013 07:30 PM BST"
""
"Venue: Theatre"
""
"Category: English Comedy"
"Discount","A",
"GENERAL ADMISSION",25.00,
"RESERVED",0.00,
"STUDENT",15.00,
"COMPLIMENTARY",0.00,
"Senior Citizen",10.00,
"SPECIAL",0.00,
""
"INT"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"GENERAL ADMISSION",79,1975.00,79,1975.00,
"Totals*",79,1975.00,79,1975.00,
""
"PBO"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"COMPLIMENTARY",2,0.00,2,0.00,
"GENERAL ADMISSION",32,800.00,32,800.00,
"RESERVED",0,0.00,0,0.00,
"Senior Citizen",4,40.00,4,40.00,
"Totals*",38,840.00,38,840.00,
""
"PHO"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"COMPLIMENTARY",10,0.00,10,0.00,
"GENERAL ADMISSION",100,2500.00,100,2500.00,
"RESERVED",0,0.00,0,0.00,
"STUDENT",4,60.00,4,60.00,
"Senior Citizen",2,20.00,2,20.00,
"Totals*",116,2580.00,116,2580.00,
""
"PERFORMANCE TOTALS"
"Discount","A","A Face Value Amt","Tickets","Face Value Amt",
"COMPLIMENTARY",12,0.00,12,0.00,
"GENERAL ADMISSION",211,5275.00,211,5275.00,
"RESERVED",0,0.00,0,0.00,
"STUDENT",4,60.00,4,60.00,
"Senior Citizen",6,60.00,6,60.00,
"Totals*",233,5395.00,233,5395.00,
""
"Abbreviated Performance Totals"
"Event","Performance Date","Discount","Tickets","Face Value Amt",
Event Four,18 Feb 2013 07:30 PM GMT,COMPLIMENTARY,12,0.00,
Event Four,18 Feb 2013 07:30 PM GMT,GENERAL ADMISSION,211,5275.00,
Event Four,18 Feb 2013 07:30 PM GMT,RESERVED,0,0.00,
Event Four,18 Feb 2013 07:30 PM GMT,STUDENT,4,60.00,
Event Four,18 Feb 2013 07:30 PM GMT,Senior Citizen,6,60.00,
,,,233,5395.00,
提前感谢任何可以提供帮助的人。