php代码|随机给域名添加新的二级
更新时间:2024-12-07 21:14:04
访问次数:90
<?php // 生成指定长度的随机字母字符串 function randomLetters($length) { $characters = 'abcdefghijklmnopqrstuvwxyz'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString.= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } // 读取文件内容 $fileContent = file_get_contents('lj.html'); // 匹配域名的正则表达式(简单示例,可根据实际更精准调整) $pattern = '/https:\/\/([a-z0-9-]+)\./'; preg_match_all($pattern, $fileContent, $matches); foreach ($matches[1] as $oldSubdomain) { // 随机决定新的二级域名长度,这里示例范围设为3到6个字母 $newLength = rand(3, 6); $newSubdomain = randomLetters($newLength); $fileContent = str_replace('https://'.$oldSubdomain.'.', 'https://'.$newSubdomain.'.', $fileContent); } // 将修改后的内容写回文件 file_put_contents('lj.html', $fileContent); ?>
网友评论