Gossamer Forum
Home : General : Internet Technologies :

Perl PHP translator

Quote Reply
Perl PHP translator
Hi,

Now I found out how nice and easy PHP works I'm converting all my perl script to PHP. Therefore I have the following question: does anywone know a perl-php dictionary type of website?

I'm having problems converting the following snippet:

Perl:
Code:
# Set statistics variable to ip and hostname.
my $ip = $ENV{'REMOTE_ADDR'};
my $hostname = scalar(gethostbyaddr(inet_aton($ip), AF_INET));
$hostname = $1 if $hostname =~ /.*\.([^.]*\.[^.]*)/;
$in{$db_cols[$db_stats]} = "$ip / $hostname";

PHP:
Code:
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($ip);
// $hostname = ???
$display = $ip." / ".$hostname;

I would like to display something like "198.45.34.45 / isp.com" (NOT "456.45.34.23 / user45.modem12.route.isp.com")
Quote Reply
Re: [cK] Perl PHP translator In reply to
Temporary I'm using

Code:
$ip = $_SERVER['REMOTE_ADDR'];
$tmp = explode(".","");
$country = array_pop ($tmp); $isp = array_pop ($tmp);
if ($isp) { $hostname = $isp.".".$country; }

But it should be able to go into a php reg. exp ;-)
Quote Reply
Re: [cK] Perl PHP translator In reply to
Have a look at the documentation for preg_match (http://php.net/preg_match), which will let you do close to the same thing in php syntax (stores the matches in an array instead of $1, $2 etc).
Quote Reply
Re: [Mark Badolato] Perl PHP translator In reply to
Thanks that's a very good reference. Stupid I didn't look there before...