}, groups : { phone:'mob_phone tel_phone' } }); }); var province=''; var city=''; var district=''; <?php /** * 根据用户ip自动默认选择省市* */ if (extension_loaded('qqwry')) { $q = new qqwry('/home/wwwroot/qqwry.dat'); $addres = $q->q(getenv("REMOTE_ADDR")); $addres[0] = iconv('GBK', "UTF-8//IGNORE", $addres[0]); if (mb_strpos($addres[0], '省') !== false) { echo "province='" . strstr($addres[0], '省', true) . "省';"; $c = strstr($addres[0], '省'); if (strpos($c, '市') !== false) { $d = mb_substr(strstr($c, '市'), 1); echo "city='" . mb_substr(strstr($c, '市', true), 1) . "市';"; } } elseif (mb_strpos($addres[0], '北京') !== false || mb_strpos($addres[0], '上海') !== false || mb_strpos($addres[0], '天津') !== false || mb_strpos($addres[0], '重庆') !== false) { echo "province='" . mb_substr($addres[0], 1) . "';"; echo "city='" . mb_substr($addres[0], 1) . "市';"; } elseif (mb_strpos($addres[0], '宁夏') !== false || mb_strpos($addres[0], '西藏') !== false || mb_strpos($addres[0], '新疆') !== false || mb_strpos($addres[0], '广西') !== false || mb_strpos($addres[0], '内蒙古') !== false) { switch (mb_substr($addres[0], 0, 2)) { case '广西': echo "province='广西壮族自治区';";
<?php $br = php_sapi_name() == "cli" ? "" : "<br>"; if (!extension_loaded('qqwry')) { dl('qqwry.' . PHP_SHLIB_SUFFIX); } $qqwry = new qqwry('/Users/surfchen/projects/qqwry/nali/php/QQWry.Dat'); list($addr1, $addr2) = $qqwry->q('127.0.0.1'); $addr1 = iconv('GB2312', 'UTF-8', $addr1); $addr2 = iconv('GB2312', 'UTF-8', $addr2); echo $addr1, '|', $addr2, "\n"; $arr = $qqwry->q('222.216.47.4'); $arr[0] = iconv('GB2312', 'UTF-8', $arr[0]); $arr[1] = iconv('GB2312', 'UTF-8', $arr[1]); echo $arr[0], '|', $arr[1], "\n"; $arr = $qqwry->q('64.233.187.99'); $arr[0] = iconv('GB2312', 'UTF-8', $arr[0]); $arr[1] = iconv('GB2312', 'UTF-8', $arr[1]); echo $arr[0], '|', $arr[1], "\n";
initConvertIp(QQWRY_PATH); echo "效率测试开始 ... "; $times = array(); $t = microtime(true); foreach ($arr as $ip) { convertip($ip); } $times[0] = microtime(true) - $t; $t = microtime(true); foreach ($arr as $ip) { $coolcode->getlocation($ip); } $times[1] = microtime(true) - $t; $t = microtime(true); foreach ($arr as $ip) { $qqwry->q($ip); } $times[2] = microtime(true) - $t; echo "测试结束\n"; echo '是discuz的', $times[0] / $times[2], "倍\n"; echo '是coolcode的', $times[1] / $times[2], "倍\n"; echo "正确性测试 ... "; foreach ($arr as $ip) { $s1 = convertip($ip); $s2 = implode('', $coolcode->getlocation($ip)); $s3 = implode('', $qqwry->q($ip)); if ($s3 != $s1 || $s3 != $s2) { echo $ip, "\n"; var_dump($s1); var_dump($s2); var_dump($s3);