|
Posted by Mladen Gogala on 08/29/05 03:22
On Sun, 28 Aug 2005 14:01:19 -0700, voipcanada wrote:
> Here is the sample text (( http://starkom.com/bill20050820_000000 ))
>
> wanted to know if there is some other function like explode to split
> the = sign in each array
This is not going to work with the simple split. You'll first have to
split using ",\s+" and then, in turn, to split each array element of the
resulting array using "=" as delimiter. The code would look like this:
#!/usr/local/bin/php
<?php
$fh = fopen("/tmp/myfile.txt", "r");
while (!feof($fh)) {
$buff = fgets($fh, 4096);
$line = preg_split("/,\s+/", "DATE=$buff");
foreach($line as $elem) {
$pair = preg_split("/=/", $elem);
@$parsed[$pair[0]] = $pair[1];
}
print_r($parsed);
$parsed = array();
}
fclose($fh);
?>
The output look like this:
Array
(
[DATE] => Sat Aug 20 18:20:20 2005
[HOST] => 66.24.17.72
[SRC-NUMBER-IN] => 8565686628
[DST-NUMBER-IN] => 888#8565487318
[SRC-NUMBER-OUT] => 8565686628
[DST-NUMBER-OUT] => 888#8565487318
[SRC-NUMBER-BILL] => 8565686628
[DST-NUMBER-BILL] => 888#8565487318
[SRC-IP] => 66.24.17.71:11298
[DST-IP] => 216.223.144.110:1720
[SRC-USER] => ANDY001IN
[DST-USER] => ANDY002OUT
[SRC-NAME] => ANDY001IN
[DST-NAME] => ANDY002OUT
[DIALPEER-NAME] => R36
[INITIAL-INCOMING-LOCAL-ADDRESS] => 66.24.17.72
[SELECTED-INCOMING-LOCAL-ADDRESS] => 66.24.17.72
[OUTGOING-LOCAL-ADDRESS] => 66.24.17.72
[RECORD-ID] => 1124534625-61
[ELAPSED-TIME] => 42
[SETUP-TIME] => 18:19:38.000 GMT Sat Aug 20 2005
[CONNECT-TIME] => 18:19:38.000 GMT Sat Aug 20 2005
[DISCONNECT-TIME] => 18:20:20.000 GMT Sat Aug 20 2005
[DISCONNECT-CODE-LOCAL] => 1
[DISCONNECT-CODE-Q931] => 16
[SRC-BYTES-IN] => 126957
[DST-BYTES-IN] => 18276
[SRC-BYTES-OUT] => 18308
[DST-BYTES-OUT] => 126494
[QOS] => 11
[SRC-CODEC] => g729
[DST-CODEC] => g729
[CALLID] => 083b3cbf10fb11da8ba0837c360ba985
[CONFID] => 083b3cbf10fb11da8b9e837c360ba985
[PROXY-MODE] => 1
[ROUTE-RETRIES] => 1
)
That is, I believe, what you want to achieve.
--
http://www.mgogala.com
Navigation:
[Reply to this message]
|