Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > HOT DO EXPLODE() THIS INTO DATABASE
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 24th February 09:35
joachim_weiß
External User
 
Posts: 1
Default HOT DO EXPLODE() THIS INTO DATABASE



voipcanada schrieb:

perhaps split is the function you are looking for.

However if you don't want to use php: man awk.

HIH

Jo
  Reply With Quote


  sponsored links


2 24th February 09:35
voipcanada
External User
 
Posts: 1
Default HOT DO EXPLODE() THIS INTO DATABASE



ok thanks ,,,,,,
  Reply With Quote
3 24th February 09:35
mladen gogala
External User
 
Posts: 1
Default HOT DO EXPLODE() THIS INTO DATABASE


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
  Reply With Quote
4 24th February 09:35
mladen gogala
External User
 
Posts: 1
Default HOT DO EXPLODE() THIS INTO DATABASE


No need for lame tools like awk. PHP can do it perfectly well.

--
http://www.mgogala.com
  Reply With Quote
5 20th March 00:36
voipcanada
External User
 
Posts: 1
Default HOT DO EXPLODE() THIS INTO DATABASE


thank you works really well ,, kind regards
  Reply With Quote
6 20th March 00:36
voipcanada
External User
 
Posts: 1
Default HOT DO EXPLODE() THIS INTO DATABASE


hi

many i ask you one more question ,,, $buff = fgets($fh, 4096); what
does 4069 mean ,,
Is it for number of lines to import ,, thanks for your responce
  Reply With Quote
7 20th March 08:59
tim van wassenhove
External User
 
Posts: 1
Default HOT DO EXPLODE() THIS INTO DATABASE


rtfm http://www.php.net/fgets

-- Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666