[SOLVED]Parts of string from text file.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Miniamba
Forum Newbie
Posts: 2
Joined: Mon Apr 04, 2011 2:11 am

[SOLVED]Parts of string from text file.

Post by Miniamba »

Hi!

I have a problem with an assignment, it's a tough one for me as I'm a beginner.
Any help will be greatly appreciated.

The file is a phone server log.
It consists of calls, and each call consists of several parts, which are:

A call= person A dials
B call= reaches person B's network
B proceed= person B's network accepts the call
B alert= person B's phone starts to ring
B connect= person B accepts the call
B rel= person B hangs up
A rel= person A hangs up

All the parts are separate inputs(strings), the two I'm interested in are the Proceed part and the Release(Rel) part.
Each string is on separate row.
An example of these from a call:

[text]?event=B:Proceed&time=1301660602&date=20110401-122322&ref=6612d8afe909d311ac9d0090331594f7&dir=out&src_if=GW1&dst_if=GW2&src_cgpn=3054&src_cdpn=53484699&dst_cgpn=53097707&dst_dgpn=53097707&dst_cdpn=53484699&src_reg_name=outsideline&bcaps=03_80_90_a3&xcoder=-,0(0,0,0)&rcoder=-,0(0,0,0)&xstats=0+0+0+0+0&rstats=0+0+0+0+0&srv_id=00-90-33-08-04-a4

?event=A:Rel&time=1301660617&date=20110401-122337&ref=6612d8afe909d311ac9d0090331594f7&dir=in&src_if=GW1&dst_if=GW2&src_cgpn=3054&src_cdpn=53484699&dst_cgpn=53097707&dst_dgpn=53097707&dst_cdpn=53484699&src_reg_name=outsideline&bcaps=03_80_90_a3&xcoder=G711A,30(0,0,0)&rcoder=G711A,30(1,0,0)&xstats=0+0+0+0+0&rstats=1+1+0+0+0&alert_time=1301660605&connect_time=1301660609&disc_time=1301660617&srv_id=00-90-33-08-04-a4
[/text]

Now, the important parts from each call are these two strings.
Every call is uniquely identified by the randomly generated string - "ref=******" [ref=6612d8afe909d311ac9d0090331594f7 in this example]
Different parameters in each part of the call are separated by the & char.
I'm only interested in the outgoing calls, which all go through the 53097707 number, which is shown in the dst_cgpn=53097707.
There are other calls that go through other numbers, but I'm only interested in the ones where dst_cgpn=53097707.
The callers number is also very important - src_cgpn. in this example src_cgpn=3054.
The third important part is the time, time= - in this example time=1301660602.
Fourth part is the date and time of the call, which is in the date part - in this example date=20110401-122337, where the date is 20110401(2011-04-01 / y-m-d)
and the time is 122337 (12:23:37).

One mayor problem for me is that the calls are overlapping, e.g some calls may be ongoing while some end or start etc.

The reason why it's necessary to look at two parts from each call (Proceed and Release) is that I need to get the duration of the call.
Which means that the difference between the time in the Proceed and the Release parts has to be taken.

The ideal result would be a table, which has:
1. column - the number, from which the call was made (src_cgpn=****).
2. column - duration of the call in seconds.
3. column - the date and time of the call.

I hope I explained the situation with enough clarity and that someone will have the time to help me.

Of course I can answer any additional questions.

Any help will be greatly appreciated.

Thanks in advance,
Miniamba.
Last edited by Miniamba on Tue Apr 12, 2011 2:01 am, edited 1 time in total.
Apocalypz
Forum Newbie
Posts: 6
Joined: Fri Nov 02, 2007 2:54 pm

Re: Parts of string from text file.

Post by Apocalypz »

So, this code here is a complete PHP page that will process the data you're interested in. You'll need a database to store the call information in. You'll also need to write a script to pull the information from the database, do some small calculations (like call duration), and display it in a table, but this will process the information for you. If you have any questions about the code let me know.

Code: Select all

if ($_GET['dst_cgpn'] != "53097707")
{
	die("Not interested in this call");
}

$callRef = $_GET['ref'];
$callerNumber = $_GET['src_cgpn'];
$time = $_GET['time'];
$date = $_GET['date'];

if ($_GET['event'] == "B:Proceed") // call moving on to B
{
	// INSERT INTO call_log (ref, callNum, startTime, date) VALUES ('$callRef','$callerNumber','$time','$date')
}
if ($_GET['event'] == "A:Rel") // call ended
{
	// UPDATE call_log SET endTime = '$time' WHERE ref = '$callRef'
}
Miniamba
Forum Newbie
Posts: 2
Joined: Mon Apr 04, 2011 2:11 am

Re: Parts of string from text file.

Post by Miniamba »

@Apocalypz.

Thanks for your response, but that's not what I need.
I think I didn't explain it properly.
I have the log as a file - example: log.txt
The idea is that the script:
opens the file,
searches for strings with B:Proceed and A:rel/B:rel (whichever comes first), and where dst_cgpn=53097707
then groups them by the ref= id,
gets the time= difference between B:Proceed and A:rel for each call (each ref=),
gets the src_cgpn= number,
gets the date,
and outputs the information for each call (each ref=) with the calling number, the duration of the call and the date.

Maybe the right way would be to explode each string into a database and then to just make a query.
Still, the .txt file size could easily be around 30mb, so that would make the application a lot slower.
What are your thoughts?

Thanks in advance,
Miniamba
Post Reply