我想从头到尾添加IP地址到
等数据库IP Address (Start) 192.168.0.0
IP Address (End) 192.168.0.10
所以它应该添加到数据库,如
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
192.168.0.6
192.168.0.7
192.168.0.8
192.168.0.9
192.168.0.10
非常感谢,我不知道。
答案 0 :(得分:2)
快速而肮脏,如果范围跨越八位字节,则需要注意
$start = '192.168.0.1';
$end = '192.168.1.255';
$startint = ip2long($start);
$endint = ip2long($end);
while ($startint <= $endint) {
echo long2ip($startint++); // replace echo with your DB insert
}
答案 1 :(得分:0)
$start = '192.168.0.';
$x = 1;
while($x < 11)
{
echo $start.$x."<br>"; // create your code to add to table
$x++;
}
PHPFiddle:http://phpfiddle.org/main/code/g9a4-qxfy