0

hey, please help me sort this data out.

Array ( [0] => Successful response for: set username [1] => Successful response for: set password [2] => Successful response for: set server [3] => Successful response for: services [4] => State Notification acquiring-network [5] => Successful response for: sign-in [6] => State Notification connecting [7] => Client Own Id Notification 5551000008535 [8] => State Notification synchronizing [9] => Enabled Services Notification PTT text-chat [10] => Enabled Services Notification PTT [11] => Client Own Name Notification "Driver 1" [12] => Client Own Name Notification "Driver 1" [13] => State Notification online [14] => Call Originating Notification chat-room 0 "" [15] => Unknown Notification [16] => ----call modified chat-room 991000008536 "Drivers"---- [17] => Unknown Notification [18] => ----call connected---- [19] => State change: acquiring-network [20] => State change: connecting [21] => Client Own Id: 5551000008535 [22] => State change: synchronizing [23] => Enabled Services: [24] => Enabled Services: [25] => Client Own Name: Driver 1 [26] => Client Own Name: Driver 1 [27] => State change: online [28] => Successful response for: get-group-members [29] => Group Contact Notification contact-list contact 5551000008539 name "Driver 2" state offline [30] => Group Contact Notification contact-list contact 5551000008540 name "Driver 3" state offline [31] => Group Contact Notification contact-list contact 5551000008541 name "Driver 4" state offline [32] => Group member contact-list False 5551000008539 [['name', 'Driver 2'], ['state', 'offline']] [33] => Group member contact-list False 5551000008540 [['name', 'Driver 3'], ['state', 'offline']] [34] => Group member contact-list False 5551000008541 [['name', 'Driver 4'], ['state', 'offline']] [35] => State Notification disconnecting [36] => Successful response for: sign-out [37] => Unknown Notification [38] => ----call ended normally---- [39] => Unknown Notification [40] => ----talker none---- [41] => Client Own Id Notification 0 [42] => State Notification offline [43] => State change: disconnecting [44] => Client Own Id: 0 [45] => State change: offline )

I need an array of users and their ID's
like:
$users = array(
'Driver 2' => '5551000008539',
'Driver 3' => '5551000008540',
etc...

Thanks

2
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by vlowe
0

You want this?

$array = //...as above...

foreach($array as $str){
	preg_match('/^Group Contact Notification contact-list contact (\d+) name "(.*)" state offline/',$str,$matches);
	if(!empty($matches)){
		$users[$matches[2]] = $matches[1];
	}
}
print_r($output);
0

hi mate,

i tried it but got blank page, this is entire script.

<?php
$user = "driver1@instant-comms.com";
$pass = "pass";

$command = "GetContacts4.py $user $pass";
exec($command, $output);

print_r($output);
?>

the output is the array in first post.
i am trying to extract the users name and id only into a $users array.

0
<?php
$user = "driver1@instant-comms.com";
$pass = "pass";
 
$command = "GetContacts4.py $user $pass";
exec($command, $output);
 
foreach($output as $str){
	preg_match('/^Group Contact Notification contact-list contact (\d+) name "(.*)" state offline/',$str,$matches);
	if(!empty($matches)){
		$users[$matches[2]] = $matches[1];
	}
}
print_r($users);
?>

SORRY - should have been print_r($users);

Edited by diafol: n/a

0

i had noticed that :p
its just not getting any matches

<?php
$user = "driver1@instant-comms.com";
$pass = "pass";
 
$command = "GetContacts4.py $user $pass";
exec($command, $output);
 
$users = array();
foreach($output as $str){
	preg_match('/^Group Contact Notification contact-list contact (\d+) name "(.*)" state offline/',$str,$matches);
	if(!empty($matches)){
		$users[$matches[2]] = $matches[1];
	} else {
		$users["Anyone"] = "Here?";
	}
}
print_r($users);
?>

Returns - Array ( [Anyone] => Here? )

0

this works for me:

$output = array(
'Group Contact Notification contact-list contact 5551000008539 name "Driver 2" state offline',
'Group Contact Notification contact-list contact 5551000008540 name "Driver 3" state offline',
'Group Contact Notification contact-list contact 5551000008541 name "Driver 4" state offline',
'Some random text'
);
foreach($output as $str){
	preg_match('/^Group Contact Notification contact-list contact (\d+) name "(.*)" state offline/',$str,$matches);
	if(!empty($matches)){
		$users[$matches[2]] = $matches[1];
	}
}
print_r($users);
0

so does this:

$output = array('Successful response for: set username','Successful response for: set password','Successful response for: set server','Successful response for: services','State Notification acquiring-network','Successful response for: sign-in','State Notification connecting','Client Own Id Notification 5551000008535','State Notification synchronizing','Enabled Services Notification PTT text-chat','Enabled Services Notification PTT','Client Own Name Notification "Driver 1"','Client Own Name Notification "Driver 1"','State Notification online','Call Originating Notification chat-room 0 ""','Unknown Notification','----call modified chat-room 991000008536 "Drivers"----','Unknown Notification','----call connected----','State change: acquiring-network','State change: connecting','Client Own Id: 5551000008535','State change: synchronizing','Enabled Services: [\'PTT\', \'text-chat\']','Enabled Services: [\'PTT\']','Client Own Name: Driver 1','Client Own Name: Driver 1','State change: online','Successful response for: get-group-members','Group Contact Notification contact-list contact 5551000008539 name "Driver 2" state offline','Group Contact Notification contact-list contact 5551000008540 name "Driver 3" state offline','Group Contact Notification contact-list contact 5551000008541 name "Driver 4" state offline','Group member contact-list False 5551000008539 [[\'name\', \'Driver 2\'], [\'state\', \'offline\']]','Group member contact-list False 5551000008540 [[\'name\', \'Driver 3\'], [\'state\', \'offline\']]','Group member contact-list False 5551000008541 [[\'name\', \'\Driver 4\'], [\'state\', \'offline\']]','State Notification disconnecting','Successful response for: sign-out','Unknown Notification','----call ended normally----','Unknown Notification','----talker none----','Client Own Id Notification 0','State Notification offline','State change: disconnecting','Client Own Id: 0','State change: offline');



foreach($output as $str){
	preg_match('/^Group Contact Notification contact-list contact (\d+) name "(.*)" state offline/',$str,$matches);
	if(!empty($matches)){
		$users[$matches[2]] = $matches[1];
	}
}
print_r($users);
0

sorry... im tired.. forgot i had tried a change in the python which changed output slightly..

works now :)

will it work

0

Sorry to be a pain, but i have dumped the python and got the results using php only.
but now the response is not in an array.

just a long string.

fwrite($sock, 'get-group-members contact-list'."\r\n");
sleep(2);
$output = fread($sock, 9000)."\n";

echo $output;

Output:
OK: set username OK: set password OK: set server state acquiring-network OK: sign-in OK: get-group-members group contact-list contact 5551000008539 name "Driver 2" state offline group contact-list contact 5551000008540 name "Driver 3" state offline group contact-list contact 5551000008541 name "Driver 4" state offline state connecting client-own-id 5551000008535 client-own-id 0 client-own-id 5551000008535 state disconnecting sign-in denied auth-error client-own-id 0 state offline

How can i extract the data into the user array as before?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.