I need a correction for my php codings of the following?
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$isptc = gethostbyaddr($ip);
$ispoh = preg_split("/./", $isptc);开发者_高级运维
$xy = count($ispoh);
$x = $xy - 1;
$y = $xy - 2;
$i = $xy - 3;
$ispp = $ispoh[$i];
$isp = $ispoh[$y] . "." . $ispoh[$x];
echo"<b>ip: $ip</b><br>";
echo"<b>isp: $ispp$isp</b>";
?>
In this above mentioned codings, i didn't get the output from $ispp and $isp.
Your first problem is using preg_split("/./")
. That will split the string on any character, not dots (because you didn't regex-escape the dot). Instead use:
$ispoh = explode(".", $isptc);
For the following code, I don't really know. That looks a bit obfuscated.
use explode()
instead.
$ip = $_SERVER['REMOTE_ADDR'];
$isptc = gethostbyaddr($ip);
$isp = array_shift(explode(".", $isptc));
echo"<b>ip: $ip</b><br>";
echo"<b>isp: $isp</b>";
You need to escape your preg_split's period:
$ispoh = preg_split("/\./", $isptc);
I Got an answers from the following PHP Codings....
<?php
$ip=$_SERVER['REMOTE_ADDR'];
$url=file_get_contents("http://whatismyipaddress.com/ip/$ip");
preg_match_all('/<th>(.*?)<\/th><td>(.*?)<\/td>/s',$url,$output,PREG_SET_ORDER);
$isp=$output[1][2];
$city=$output[9][2];
$state=$output[8][2];
$zipcode=$output[12][2];
$country=$output[7][2];
?>
<body>
<table align="center">
<tr><td>ISP :</td><td><?php echo $isp;?></td></tr>
<tr><td>City :</td><td><?php echo $city;?></td></tr>
<tr><td>State :</td><td><?php echo $state;?></td></tr>
<tr><td>Zipcode :</td><td><?php echo $zipcode;?></td></tr>
<tr><td>Country :</td><td><?php echo $country;?></td></tr>
</table>
</body>
精彩评论