Home >Backend Development >PHP Tutorial >PHP script to calculate whether they are in the same subnet_PHP tutorial

PHP script to calculate whether they are in the same subnet_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:21:36846browse

/*
For example: 192.16.1.13
and: 255.255.255.0
, and calculate, it is required to be 192.16.1.0
*/
$ip = "192.16.1.13";
echo get_net($ip,"255.255.255.0");

function get_net($ip,$hide="255.255.255.255") {
$a = explode(".",$ip);
$b = explode(".",$hide) ;

for($i=0;$i<4;$i++)
$r[$i] = (int)$a[$i] & (int)$b[$i];
return join(".",$r);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532403.htmlTechArticle?php /* For example: 192.16.1.13 and: 255.255.255.0, and calculate, to find it is 192.16.1.0 */ $ip = "192.16.1.13"; echo get_net($ip,"255.255.255.0"); function get_net($ip,$hide="255.255.2...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn