Jump to content

Adding New Function in Current Code


asterdeve

Recommended Posts

Viewers, Thanks for watching I hope one of you will help me soon, below is my function of Codeignitor.

function status()
{
$org = Array ( [0] => Response: Follows [1] => Privilege: Command [2] => Name/username Host Dyn Forcerport ACL Port Status [3] => Test-Call 198.15.126.41 5060 OK (256 ms) [4] => rutest/rutest (Unspecified) D 0 UNKNOWN [5] => simpro/simpro (Unspecified) D 0 UNKNOWN [6] => test2 79.115.39.65 5060 UNREACHABLE [7] => 4 sip peers [Monitored: 1 online, 3 offline Unmonitored: 0 online, 0 offline] [8] => --END COMMAND-- [9] => );

$this->db->where('status',1);
$query=$this->db->get('simpro_originator');
$results=$query->result_array();
foreach($results as $row)
{
$data[$i]['id']=$row['id'];
$data[$i]['name']=$row['name'];
$data[$i]['pass']=$row['pass'];
$data[$i]['orig_ip']=$row['orig_ip'];
$data[$i]['call_limit']=$row['call_limit'];
$data[$i]['status']=$row['status'];
$data[$i]['created_on']=$row['created_on'];
foreach($org as $str)
{

if(stripos($str,$row['orig_ip']))
{
if(stripos($str,'OK'))
{
$data[$i]['active']='OK';
}
else
$data[$i]['active']='NOTOK';
}
}

$i++;
}
print_r($data);
return data = {"":{"id":"1","name":"Test-Call","pass":"Google","orig_ip":"198.15.126.41","call_limit":"128","status":"1","created_on":"2018-01-14 08:04:44","active":"OK"},"1":{"id":"2","name":"test2","pass":"sfsdfsa","orig_ip":"79.115.39.65","call_limit":"64","status":"1","created_on":"2018-03-08 01:07:02","active":"NOTOK"}}
}
}
So as you can see I get active: OK or NOTOK, I want it will also show another array with name latency: Result or N/A, check on $org = which IP result is OK with that result there is latency OK (256 ms), so I want to get that result in array too without ( ) like this "active":"OK or NOTOK" & "latency":"256 ms or N/A"

I hope I clarified my question & someone will able to help me ASAP, Thanks in advance.

Edited by requinix
please use the Code <> button when posting code
Link to comment
Share on other sites

That's clearly not the code you're using: it's not valid. The $org thing at the top and the data= bit at the bottom. PHP will refuse to execute the file containing this.

 

So what is the real code? If you need to get the latency from $org then we have to see what $org actually is.

Link to comment
Share on other sites

Okay then...

 

You have to figure out which of the $org lines contains the latency information. Your code already does that. Then you can use a regular expression to extract the value.

preg_match('/\((\d+) ms\)/', $str, $match)
Learn about preg_match and how to use it, then you can get the latency value from $match[1].
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.