例如,是否可以采用以下网址:
https://www.example.com/en/blah/blah
但是用传递的变量替换“ en”吗?
我拥有的PHP :(下面返回的URL与上面的类似)
'href' => $this->url->link($route, $url)
我可以使用新的语言变量
$result['url_code']
但是运气不好,用结果变量替换了第一个url部分来替换返回的链接。
返回的URL带有/ * /路径的第一部分的初始URL将根据语言而变化,因此需要用变量$result['url_code']
替换第一部分中的任何内容
有什么想法吗?
答案 0 :(得分:1)
您可能希望查看parse_url()
来解构您拥有的值,然后重新构建它。当然,这比需要的更为冗长,但是它确实可靠地完成了工作,并且在某些情况下不会中断。
<?php
$url = $this->url->link($route, $url);
$url_parts = parse_url($url);
$path_parts = explode("/", $url_parts["path"]);
// there's a leading slash, so [0] is an empty string
$path_parts[1] = $result['url_code'];
$path = implode("/", $path_parts);
$new_url = "$url_parts[scheme]://$url_parts[host]$path";
if (!empty($url_parts["query"])) {
$new_url .= "?$url_parts[query]";
}
答案 1 :(得分:0)
days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
daysIter = iter(days)
timeslots = ["8:00AM","8:30AM","9:00AM","9:30AM","10:00AM","10:30AM","11:00AM","11:30AM",
"12:00PM","12:30PM","1:00PM","1:30PM","2:00PM","2:30PM","3:00PM","3:30PM","4:00PM","4:30PM",
"5:00PM","5:30PM","6:00PM","6:30PM","7:00PM","7:30PM","8:00PM","8:30PM","9:00PM","9:30PM"]
timesIter = iter(timeslots)
daysonsheet = sheet.range("A2:A7")
timesonsheet = sheet.range("C1:AD1")
sheet.update_acell('A1',days[0])
for cell in daysonsheet:
cell.value = next(daysIter)
sheet.update_cells(daysonsheet)
sheet.update_acell('B1',timeslots[0])
for cell1 in timeslots:
cell1.value = next(timesIter)
sheet.update_cells(timesonsheet)
在复制此内容之前,请先阅读