For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > August 2005 > $alines = preg_split("/=/", $lines);









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author $alines = preg_split("/=/", $lines);
voipcanada

2005-08-28, 9:55 pm

is there any thing we can write to keep the right txt to the = sign in
the preg_split. from the following lines

DST-NUMBER-IN=0033512877596, DST-NUMBER-OUT=98751#33512877596,
DST-NUMBER-BILL=0033512877596

i only want 0033512877596, 98751#33512877596, 0033512877596

Mladen Gogala

2005-08-28, 9:55 pm

On Sun, 28 Aug 2005 17:54:52 -0700, voipcanada wrote:

> is there any thing we can write to keep the right txt to the = sign in
> the preg_split. from the following lines
>
> DST-NUMBER-IN=0033512877596, DST-NUMBER-OUT=98751#33512877596,
> DST-NUMBER-BILL=0033512877596
>
> i only want 0033512877596, 98751#33512877596, 0033512877596


I believe that already answered this. What do you mean by "keep the right
txt to the = sign"?

--
http://www.mgogala.com

voipcanada

2005-08-28, 9:55 pm

no one answered this till now, i need to know the exact code to be
written ,, kind regards

macbri

2005-08-28, 9:55 pm


You could use preg_replace() instead:


Code:
--------------------

$alines = preg_replace("/[^=]+=/", "", $lines);

--------------------


--
macbri
------------------------------------------------------------------------
macbri's Profile: http://www.macosx.com/forums/member.php?userid=34415
View this thread: http://www.macosx.com/forums/showthread.php?t=242019
macosx.com - The Answer to Mac Support - http://www.macosx.com

Mladen Gogala

2005-08-28, 9:55 pm

On Sun, 28 Aug 2005 18:13:58 -0700, voipcanada wrote:

> no one answered this till now, i need to know the exact code to be
> written ,, kind regards


Look at your previous post and my response.

--
http://www.mgogala.com

voipcanada

2005-08-28, 9:55 pm

Dear Macbri

it does work good but not when we want a file like this to be edited
,,,, please look at the file and if you can suggest some thing
http://starkom.com/bill20050820_000000 .. thanks and regards

Mladen Gogala

2005-08-28, 9:55 pm

On Sun, 28 Aug 2005 18:24:19 -0700, voipcanada wrote:

> Dear Macbri


Plonk.

--
http://www.mgogala.com

voipcanada

2005-08-28, 9:55 pm

dear Mladen Gogala

i tryed your suggestions but it does not work ,,,, i need to replace
the in the file above ,, thanks

macbri

2005-08-29, 3:55 am


voipcanada Wrote:
> Dear Macbri
>
> it does work good but not when we want a file like this to be edited
> ,,,, please look at the file and if you can suggest some thing
> http://starkom.com/bill20050820_000000 .. thanks and regards

Why not split each line with preg_split() and then use the
preg_replace() as described....?


Code:
--------------------
foreach ($lines as $each) {
$line = preg_split("/,/", $each);
$line = preg_replace ... (etc.)
}
--------------------


--
macbri
------------------------------------------------------------------------
macbri's Profile: http://www.macosx.com/forums/member.php?userid=34415
View this thread: http://www.macosx.com/forums/showthread.php?t=242019
macosx.com - The Answer to Mac Support - http://www.macosx.com

kerul4u

2005-08-29, 6:56 pm

Instead of using preg_split why not trying to reading and writing file

try out this

//Suppose Your file is bill20050820_000000.txt
$file = "bill20050820_000000.txt";
$fp = fopen($file,'r');
$string = fread($fp, filesize($file));
fclose($fp);
//Array of special charecters you want to replace
$special =
array('DST-NUMBER-IN=','DST-NUMBER-OUT=','DST-NUMBER-BILL=');
$replacements = "";

$string = str_replace($special,$replacements,$stri
ng);
//Write back to file
$fp = fopen($file,'w');
fwrite($fp, $string);
fclose($fp);

+++++++++++++++++
if you find it useful plz notify me
KERUL
[ProDesignZ]

voipcanada

2005-08-29, 6:56 pm

thanks to your so much ,, kind regards

macbri

2005-08-29, 6:56 pm


kerul4u Wrote:
> Instead of using preg_split why not trying to reading and writing file
>
> --snip--
> //Array of special charecters you want to replace
> $special =
> array('DST-NUMBER-IN=','DST-NUMBER-OUT=','DST-NUMBER-BILL=');
> $replacements = "";
>
> $string = str_replace($special,$replacements,$stri
ng);
> --snip--


Not a bad idea, but if you look at the contents of the OP's actual file
there's a lot of other stuff in there. Especially dates, IP addresses
etc. Your array of special characters might become a bit unwieldy:

>
> Sat Aug 20 10:59:31 2005, HOST=xxx.xxx.xxx.xxx,
> DST-NUMBER-IN=003351xxxxxxxx, DST-NUMBER-OUT=98751#33512xxxxxxxx,
> DST-NUMBER-BILL=003351xxxxxxxx, SRC-IP=xxx.xxx.xxx.xxx:1456,
> DST-IP=xxx.xxx.xxx.xxx.246:1720, SRC-USER=125, DST-USER=easylink,
> SRC-NAME=U11, DST-NAME=easylink, DIALPEER-NAME=R30,
> INITIAL-INCOMING-LOCAL-ADDRESS=xxx.xxx.xxx.xxx,
> SELECTED-INCOMING-LOCAL-ADDRESS=xxx.xxx.xxx.xxx,
> OUTGOING-LOCAL-ADDRESS=xxx.xxx.xxx.xxx, RECORD-ID=1124534625-0,
> ELAPSED-TIME=0, SETUP-TIME=10:59:31.000 GMT Sat Aug 20 2005,
> CONNECT-TIME=10:59:31.000 GMT Sat Aug 20 2005,
> DISCONNECT-TIME=10:59:31.000 GMT Sat Aug 20 2005,
> DISCONNECT-CODE-LOCAL=2, DISCONNECT-CODE-Q931=1, SRC-BYTES-IN=604,
> DST-BYTES-IN=95, SRC-BYTES-OUT=0, DST-BYTES-OUT=630, QOS=0,
> SRC-CODEC=g729B g729 g729AwB g729A g7231 gsmFR g711U64k g711A64k ,
> CALLID=0221d499c177861a56343xxxxxxxxxxxx
,
> CONFID=0221d499c17bc32456343xxxxxxxxxx, PROXY-MODE=1, ROUTE-RETRIES=1


But, based on the OP's latest reply, I guess he/she has a solution that
works, so the point is moot now anyway :)


--
macbri
------------------------------------------------------------------------
macbri's Profile: http://www.macosx.com/forums/member.php?userid=34415
View this thread: http://www.macosx.com/forums/showthread.php?t=242019
macosx.com - The Answer to Mac Support - http://www.macosx.com

voipcanada

2005-08-30, 3:55 am

hi all the colums were added ,,,, fi there is any other suggestions ,,
let me know

$fp = fopen($fname,'r');
$string = fread($fp, filesize($fname));
fclose($fp);
//Array of special charecters you want to replace
$special =
array('DST-NUMBER-IN=','DST-NUMBER-OUT=','DST-NUMBER-BILL=','HOST=','SRC-IP=','DST-IP=','SRC-USER=','DST-USER=','SRC-NAME=','DST-NAME=','DIALPEER-NAME=','INITIAL-INCOMING-LOCAL-ADDRESS=','SELECTED-INCOMING-LOCAL-ADDRESS=','OUTGOING-LOCAL-ADDRESS=','RECORD
-ID=','ELAPSED-TIME=','SETUP-TIME=','DISCONNECT-TIME=','DISCONNECT-CODE-LOCAL=','DISCONNECT-CODE-Q931=');
$replacements = "";

$string = str_replace($special,$replacements,$stri
ng);
//Write back to file
$fp = fopen($fname,'w');
fwrite($fp, $string);
fclose($fp);

kerul4u

2005-08-30, 3:55 am

hi,

if it works for you its the better way..if having any problem state it
here so we can give other suggetion.

KERUL
[ProDesignZ]

kerul4u

2005-08-30, 3:55 am

hey,

I've look at your previous posts.
You are posting the same problem with diff. presentation.
Wat it mean man? What you want exactly?
Do you need someone to write code for you? Cause after looking your
previous post I can guess u don't know PHP.
If so plz don't waste your and others time. Just directly post wat you
want and wat you need.

KERUL
[ProDesignZ]

voipcanada

2005-08-30, 6:56 pm

dear kerul4u

yes that will befine let me know if you are looking for some
compensation on this ,,,

our server can dumps CDR every day in a file like above, we can make it
dump CDRs every 10 mins or 1 hours or daily

the text files need to be imported into a database and charged
accroding to an rate table and also then zipped to save space

if you can tie this up to an cron job that will be best , we use
freebsd as servers

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com