I need to be able to parse this sort of data in PHP:
Acct: 1
email : [email protected]
status : online
--------------------------------------------------
Acct: 2
email : [email protected]
status : banned
--------------------------------------------------
Acct: 3
signedupname : SomeUsername
somethingelse : offline
--------------------------------------------------
As you can see the data is largely random. The only thing that remains the same is the -----
seperating each entry and the Acct: 1
bits. The padding between each :
often changes as does the variable to represent each bit of data.
I've tried going through and parsing it all myself using regex but I am defenately not skilled enough to be able to do it properly. At the end of this I want data according to the following:
Acct: <integer>
var1: <string>
var2: <string>
If that makes any sense at all. It doesn't need to be that effeciant, as I will need to do this about once a day and I do not mind waiting for how-ever long it needs.
Thank you. :)
Edit: This is what I did on my own:
<?php
$data = file_get_contents('records.txt');
$data = explode('******** Saved Host list with acct/variables ********', $data);
$data = explode('--------------------------------------------------', $data[1]);
foreach($data as &$dataz)
{
$dataz = trim($dataz);
}
$data = str_replace('Acct:', "\nAcct:", $data);
foreach($data as $dataz)
{
preg_match('/Acct: (.*)/', $dataz, $match);
$acct = $match[1];
preg_match('/: (.*)/', $dataz, $match);
$var1 = $match[1];
echo $var1;
}
?>
I got as far as extracting the Acct:
part, but anything beyond that I simply can't get my head around.