Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
<?php /** * 生成营业执照代码 * @param string $region 区域,支持 'yantai'(烟台)和 'weihai'(威海) * @return string 生成的营业执照代码,如果区域不支持则返回空字符串 */ function generateBusinessLicenseCode($region) { // 定义区域前缀 $prefixes = [ 'yantai' => '91370600', 'weihai' => '91371081' ]; // 检查区域是否支持 if (!array_key_exists($region, $prefixes)) { return ''; } // 获取区域前缀 $prefix = $prefixes[$region]; // 生成随机数字部分(8位) $randomDigits = ''; for ($i = 0; $i < 8; $i++) { $randomDigits .= rand(0, 9); } // 组合前14位代码 $code14 = $prefix . $randomDigits; // 计算校验码 $checkCode = calculateCheckCode($code14); // 返回完整的营业执照代码 return $code14 . $checkCode; } /** * 计算营业执照代码的校验码 * @param string $code14 前14位代码 * @return string 校验码 */ function calculateCheckCode($code14) { // 定义加权因子 $factors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24]; // 定义字符集 $charset = '0123456789ABCDEFGHJKLMNPQRTUWXY'; // 计算加权和 $sum = 0; for ($i = 0; $i < 14; $i++) { $char = $code14[$i]; $pos = strpos($charset, $char); $sum += $pos * $factors[$i]; } // 计算模 $mod = $sum % 31; // 返回校验码 return $charset[31 - $mod]; } // 生成指定区域和数量的营业执照代码 function generateLicenseCodes($region, $count) { $codes = []; for ($i = 0; $i < $count; $i++) { $codes[] = generateBusinessLicenseCode($region); } return $codes; } // 生成烟台和威海各100个营业执照代码 $yantaiCodes = generateLicenseCodes('yantai', 100); $weihaiCodes = generateLicenseCodes('weihai', 100); // 输出结果 echo "烟台营业执照代码(100个):\n"; foreach ($yantaiCodes as $code) { echo $code . "\n"; } echo "\n威海营业执照代码(100个):\n"; foreach ($weihaiCodes as $code) { echo $code . "\n"; } ?>

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // 生成烟台、威海地区的手机号,支持四大运营商 // 定义运营商前缀 $prefixes = [ // 移动 'cmcc' => [ '134', '135', '136', '137', '138', '139', '147', '150', '151', '152', '157', '158', '159', '172', '178', '182', '183', '184', '187', '188', '198' ], // 联通 'cucc' => [ '130', '131', '132', '145', '155', '156', '166', '171', '175', '176', '185', '186' ], // 电信 'ctcc' => [ '133', '149', '153', '173', '174', '177', '180', '181', '189', '191', '199' ], // 广电 'crtc' => [ '192' ] ]; // 烟台、威海的地区码 $areaCodes = [ 'yantai' => [357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369], 'weihai' => [356, 369] // 部分重叠 ]; // 随机生成一个手机号 function generatePhoneNumber($prefixes, $areaCodes) { // 随机选择运营商 $operators = array_keys($prefixes); $operator = $operators[array_rand($operators)]; // 随机选择该运营商的前缀 $prefix = $prefixes[$operator][array_rand($prefixes[$operator])]; // 随机选择地区(烟台或威海) $cities = array_keys($areaCodes); $city = $cities[array_rand($cities)]; // 随机选择该地区的号码段 $areaCode = $areaCodes[$city][array_rand($areaCodes[$city])]; // 随机生成后四位 $suffix = rand(1000, 9999); return [ 'phone' => $prefix . $areaCode . $suffix, 'operator' => $operator, 'city' => $city ]; } // 生成指定数量的手机号 $count = 20; $phones = []; for ($i = 0; $i < $count; $i++) { $phones[] = generatePhoneNumber($prefixes, $areaCodes); } // 输出结果 header('Content-Type: application/json'); echo json_encode($phones, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); ?>
Copy Clear