ファイルの各行をループし、各行に正規表現を適用して取得できます
//I am just constructing $lines array assuming you have all lines of the file
$lines[0] = "200A-200B. Civil Procedure. (3) The principles of pleading under the code system and the federal rules;
modern trial practice, including venue, process, the jury, sufficiency of evidence, instructions, verdicts, new trials, judgments; appellate procedure. Ms. Aldave, Mr. Louisell, Mr. Poche, Mr. Stolz, Mr. Vetter";
$lines[1] = "201A-201B. Contracts. (4) The law of contracts, dealing with the prob¬lems of formation, operation, and termination. Mr. Eisenberg, Mr. Kessler, Mr. Laube, Mr. Weintraub";
$regex = '/(.*)\.\s*(.*)\.\s*\(([1-9]+)\)\s*([^\..]*)\.\s*(.*)\s*$/';
$data = array();
foreach($lines as $line)
{
preg_match($regex, $line, $matches);
if(isset($matches[1]) &&
isset($matches[2]) &&
isset($matches[3]) &&
isset($matches[4]) &&
isset($matches[5])
)
$data[] = array("class_code" => $matches[1],
"class_name" => $matches[2],
"class_unit" => $matches[3],
"class_description" => $matches[4],
"class_instructors" => $matches[5]
);
}
上記の$data
変数を var_dump すると、次の出力が得られます。
array
0 =>
array
'class_code' => string '200A-200B' (length=9)
'class_name' => string 'Civil Procedure' (length=15)
'class_unit' => string '3' (length=1)
'class_description' => string 'The principles of pleading under the code system and the federal rules;
modern trial practice, including venue, process, the jury, sufficiency of evidence, instructions, verdicts, new trials, judgments; appellate procedure' (length=222)
'class_instructors' => string 'Ms. Aldave, Mr. Louisell, Mr. Poche, Mr. Stolz, Mr. Vetter' (length=58)
1 =>
array
'class_code' => string '201A-201B' (length=9)
'class_name' => string 'Contracts' (length=9)
'class_unit' => string '4' (length=1)
'class_description' => string 'The law of contracts, dealing with the prob¬lems of formation, operation, and termination' (length=90)
'class_instructors' => string 'Mr. Eisenberg, Mr. Kessler, Mr. Laube, Mr. Weintraub' (length=52)
それがあなたが探しているものであることを願っています..