php从字符串生成html页面
我使用这个脚本为公司从.xls列表中获得的每个门店位置生成静态html页面,然后脚本根据关键字字符串对门店位置后的URL进行编码 目前的情况是:php从字符串生成html页面,php,html,Php,Html,我使用这个脚本为公司从.xls列表中获得的每个门店位置生成静态html页面,然后脚本根据关键字字符串对门店位置后的URL进行编码 目前的情况是: keyword_string = "key1 key2 key3 key4 key5"; function urlX($location) { return $this->xURL($location).'/'.urlencode($this->keyword_string).'.html'; } 如何让它读取关
keyword_string = "key1 key2 key3 key4 key5";
function urlX($location) {
return $this->xURL($location).'/'.urlencode($this->keyword_string).'.html';
}
如何让它读取关键字字符串的2个甚至3个变体,并将html URL编码随机化?这将创建真正的随机链接。如果您希望有一组关键字字符串集(即:关键字字符串集1=“key1 key2 key3”,关键字字符串集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_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");
您将html URL编码随机化到底是什么意思?urlencode是一个函数,它返回一个字符串,并将另一个字符串作为参数。您想随机化什么?您是否希望使用从$keyword\u字符串中选取的随机键生成链接?这可以通过创建一个数组并选择一个随机键来实现。@AndreiCristianProdan脚本当前正在为每个位置创建相同的url,如下所示:location1/key1+key2+key3.html location2/key1+key2+key3.html,我正在尝试实现的是:location1/key1+key2+key3.html location2/key3+key1+key3.html location3等user1145643你能给我一个例子吗?我将如何在脚本中实现它?是的,我认为能够从一些预设的关键字字符串选项中进行选择将是一种更好的方式,因为我有更多的控制权。@user1154643你能告诉我如何在脚本中实现它吗?@user1154643这将使链接随机化但是每次刷新页面时,都会出现一组新的链接,它应该只随机化一次,而不是打印位置名称数组:@user1154643我设法使其适应脚本,所以现在城市名称工作正常,只是每次刷新页面时,随机链接都会不断变化还有一个非常奇怪的问题,无论你的url是什么,它都会加载页面。你可以+把+放在这里+任何你想要的+和+页面+仍然+加载.html
$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");