PHP - 在 URL 中用 https 替换 http

标签 php html checkbox

一旦用户选中 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/

相关文章:

java - 使用 php 和 MySql 在 android 中检查复选框

javascript - 如果使用 javascript 选中复选框,如何重定向到特定链接?

php - 拉维尔 5.4 : JWT API with multi-auth on two tables one works the other not

php - 如何在 auth Only Continue Transaction 类型中设置订单发票编号和描述?

javascript - 如果名称和值与输入复选框字段匹配,请检查复选框

html - 将 li 图标更改为 font awesome 图标

javascript - 如何通过鼠标悬停与 css 显示/隐藏彼此之外的两个单独的 DIV

javascript - Ajax如何对多种表单的数据字段进行优先级排序?

php - Backbone UI 和 CMS 后端 : Wading through the Restful CRUD

html - CSS 不链接到 HTML