这将创建真正随机的链接。如果您希望拥有一组关键字字符串集(即:keyword_string_1 = "key1 key2 key3"、keyword_string_2 = "key2 key3 key1" 等...)并选择一个随机集附加到每个位置,此方法可以是在更简单的尺度上使用。可能还有几种方法可以加快速度。
$keyword_string = "key1 key2 key3 key4 key5";
function urlX($location) {
global $keyword_string;
$keyword_string = @explode(" ", $keyword_string);
if(is_array($keyword_string)){
$total = count($keyword_string);
$random_keys = Array();
for($i=0; $i<$total; $i++){
$new = rand(0,$total-1);
while(in_array($new,$random_keys)){
$new = rand(0,$total-1);
}
array_push($random_keys, $new);
}
}
$page = "";
foreach($random_keys as $key){
$page .= $keyword_string[$key] . " ";
}
return $location . "/" . urlencode(trim($page)) . ".html";
}
新增:
这是适用于一组随机字符串的上述代码。您可以预加载其他字符串并将它们添加到$keyword_string
数组的末尾。
$keyword_string_1 = "key1 key2 key3 key4 key5";
$keyword_string_2 = "key2 key3 key4 key5 key1";
$keyword_string_3 = "key3 key4 key5 key1 key2";
/// ADD MORE HERE IF YOU LIKE
$keyword_string = Array($keyword_string_1, $keyword_string_2, $keyword_string_3);
function urlX($location) {
global $keyword_string;
if(is_array($keyword_string)){
$total = count($keyword_string);
$random_keys = Array();
$page = $keyword_string[rand(0,$total-1)];
}
return $location . "/" . urlencode(trim($page)) . ".html";
}
print urlX("http://www.google.com"); /// SIMPLE CALL TO NEW FUNCTION urlX()
新增:
$keyword_string_1 = "key1 key2 key3 key4 key5";
$keyword_string_2 = "key2 key3 key4 key5 key1";
$keyword_string_3 = "key3 key4 key5 key1 key2";
function urlX($location) {
global $keyword_string_1, $keyword_string_2, $keyword_string_3;
if($location == "http://www.url1.com"){ /// CHANGE THESE TO ACTUAL URLS
return $location . "/" . urlencode($keyword_string_1) . ".html";
}else if($location == "http://www.url2.com"){
return $location . "/" . urlencode($keyword_string_2) . ".html";
}else if($location == "http://www.url3.com"){
return $location . "/" . urlencode($keyword_string_3) . ".html";
}else{
return false;
}
}
print urlX("http://www.url1.com");