Solved

convert perl routine to php - Get Cisco phone IP information

Posted on 2010-08-26
2
345 Views
Last Modified: 2012-05-10
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
Comment
Question by:tgeddings
2 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 33538125
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
 

Accepted Solution

by:
tgeddings earned 0 total points
ID: 33538185
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question