$rv){ if(array_key_exists($rk, $GLOBALS['arr_whitelist'])){//主域名在白名单的,整个不写入屏蔽列表 continue; } if(empty($rk)){//遗漏的域名,不会写入到最终的配置里 // print_r($rv); continue; } if(!is_array($rv)){ if(array_key_exists($rv, $GLOBALS['arr_whitelist'])){//单个域名的白名单检查 continue; } $write_len += fwrite($fp, str_replace('{DOMAIN}', $rv, $formatObj['format']) . "\n"); continue; } $rv = array_unique($rv); if(in_array('.' . $rk, $rv) || in_array('www.' . $rk, $rv) || in_array($rk, $rv)){ $write_len += fwrite($fp, str_replace('{DOMAIN}', $rk, $formatObj['format']) . "\n"); continue; } $arr_written = []; foreach($rv as $rvv){ if(array_key_exists($rvv, $GLOBALS['arr_whitelist'])){ continue; } //合并三级域名逻辑 $tmp_arr1 = explode('.', $rvv); $written_flag = false; if(count($tmp_arr1) > 2){ for($tmp_pos = 3; $tmp_pos <= count($tmp_arr1); $tmp_pos++){ $tmp_arr2 = array_slice($tmp_arr1, -1 * $tmp_pos); if(in_array(implode('.', $tmp_arr2), $rv)){ if(!in_array(implode('.', $tmp_arr2), $arr_written)){ $arr_written[] = implode('.', $tmp_arr2); if(array_key_exists(implode('.', $tmp_arr2), $GLOBALS['arr_whitelist'])){ continue; } $write_len += fwrite($fp, str_replace('{DOMAIN}', implode('.', $tmp_arr2), $formatObj['format']) . "\n"); } $written_flag = true; break; } } } if(in_array($rvv, $arr_written) || $written_flag){ continue; } $arr_written[] = $rvv; $write_len += fwrite($fp, str_replace('{DOMAIN}', $rvv, $formatObj['format']) . "\n"); } } fclose($fp); return $write_len; } }