• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

convert perl routine to php - Get Cisco phone IP information

I have a perl script that returns the extension from a Cisco phone that calls it from its internal browser.  It works as follows:

sub getphoneextension
{
      my ($phoneip) = @_;
      my $url = "http://". $phoneip . "/DeviceInformationX";
      my $page = &getPhoneInfo($url);
      my $phoneEXT='';
      my $xmldoc = XMLin($page, ContentKey => '-content');
      $phoneEXT = $xmldoc->{phoneDN};
            
      return $phoneEXT;
}

sub getPhoneInfo
{
      my ($url) = @_;
      $doc = get $url;
      
      return $doc;
}


I need to accomplish the same thing in a PHP script.  Here is my unsuccessful attempt:

# Get Phone Extension
$phoneip=@$REMOTE_ADDR;

$url = "http://";
$url .= $phoneip;
$url .= "/DeviceInformationX";
# print $phoneip;

 $ch = curl_init();
$timeout = 5;
 // set to zero for no timeout
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$result = curl_exec($ch);
curl_close($ch);
$rss = simplexml_load_string($result);

# $rss =  simplexml_load_file('http://'.$phoneip.'/DeviceInformationX');

// Extract only the digits from phoneDN.
preg_match('{(\d+)}', $rss->phoneDN, $digits);

$phoneEXT = $digits;


Please give the correct PHP script.

Thanks.
0
tgeddings
Asked:
tgeddings
1 Solution
 
Terry WoodsIT GuruCommented:
It's hard for me to know where it's going wrong because I don't have a similar system to work with. Perhaps you could print the output of:
simplexml_load_string($result);
and that might give us something to work with.
0
 
tgeddingsAuthor Commented:
I figured it out shortly after posting this.  Everything was correct except:

$phoneEXT = $digits;

should have been:

$phoneEXT = $digits[1];

The simple things always seem hard..

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now