我有一个文本文件,它有大约 5,000 行,每行大约 200 个字符长。每行实际上包含 6 条不同的数据,我一直在使用这些数据substr()
来分解它们。例如,在每一行中,字符 0 - 10 包含 Client#,字符 10-20 包含 Matter#,等等。这一切都很好,运行速度比我需要的还要快。
当我的老板告诉我客户编号有 4 个前导零并且需要去掉它们时,我的问题就出现了。所以我想,没问题 - 我只是将我的第一个substr()
函数从substr(0, 10)
(从 0 开始,取 10 个字符)改为substr(4, 6)
(从第 4 个字符开始,只取 6 个),这将跳过 4 个前导零,我会很好走。
但是,当我将其更改为时substr(0, 10)
,substr(4,6)
该过程会停止并需要永远完成。为什么是这样?
这是我的代码片段:
// open the file
$file_matters = fopen($varStoredIn_matters,"r") or exit("Unable to open file!");
// run until the end of the file
while(!feof($file_matters))
{
// place current line in temp variable
$tempLine_matters = fgets($file_matters);
// increment the matters line count
$linecount_matters++;
// break up each column
$clientID = trim(substr($tempLine_matters, 0, 10)); // THIS ONE WORKS FINE
//$clientID = trim(substr($tempLine_matters, 4, 6)); // THIS ONE MAKES THE PROCESS GRIND TO A HALT!!
$matterID = trim(substr($tempLine_matters, 10, 10));
//$matterID = trim(substr($tempLine_matters, 15, 5));
$matterName = trim(substr($tempLine_matters, 20, 80));
$subMatterName = trim(substr($tempLine_matters, 100, 80));
$dateOpen = trim(substr($tempLine_matters, 180, 10));
$orgAttorney = trim(substr($tempLine_matters, 190, 3));
$bilAttorney = trim(substr($tempLine_matters, 193, 3));
$resAttorney = trim(substr($tempLine_matters, 196, 3));
//$tolCode = trim(substr($tempLine_matters, 200, 3));
$tolCode = trim(substr($tempLine_matters, 200, 3));
$dateClosed = trim(substr($tempLine_matters, 203, 10));
// just does an insert into the DB using the variables above
}