一旦用户选中 html 表单中的框,我正在尝试弄清楚如何在 HTTP 之后添加 s。
我的 PHP 中有,
$url = 'http://google.com';
if(!isset($_POST['https'])) {
//something here
}
所以基本上,当用户选中名称为“https”的框时,我想将 s 添加到 $url 的 http 中,使其成为 https://google.com .
我对 PHP 知之甚少,如果有人可以向我解释如何进行此操作,这将非常有帮助!谢谢。
最佳答案
$url = preg_replace("/^http:/i", "https:", $url);
关于PHP - 在 URL 中用 https 替换 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5289272/