If you don't have a rather large file, preg match will do what you want:
Data.txt:
Code:
fsaffjsf some unrelated data
sdsds
sgfag
238123942
------
----------------------
Total : 26.225 %
--------------------------
dsd
sdaffgasf35515
2------------
23----
---------------------------
Monkeys : Furry
--------------------
sds
afaf
PHP Code:
$Content = file_get_content('Data.txt');
preg_match_all('~\s{4}[\r\n-]+\s*(.+):(.+)\s*[\r\n-]+~m', $Content, $Matches);
$Data = array();
for($i = 0; $i < count($Matches[1]); $i++){
$Field = trim($Matches[1][$i]);
$Value = trim($Matches[2][$i]);
$Data[$Field] = $Value;
}
var_dump($Data);
Output:
Code:
array(2) {
["Total"]=>
string(8) "26.225 %"
["Monkeys"]=>
string(5) "Furry"
}
If you just want an array of matching lines and no parsing the data, then:
PHP Code:
preg_match_all('~\s{4}[\r\n-]+\s*(.+)\s*[\r\n-]+~m', $Content, $Matches);
$Data = array();
foreach($Matches[1] as $Match){
$Data[] = trim($Match);
}
Output:
Code:
array(2) {
[0]=>
string(22) "Total : 26.225 %"
[1]=>
string(16) "Monkeys : Furry"
}
Bookmarks