Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - replace http with https in URL

Tags:

I am trying to figure out how to add s after HTTP once a user checks a box in the html form.

I have in my PHP,

$url = 'http://google.com';  if(!isset($_POST['https'])) {    //something here } 

So basically, when the user checks a box with the name="https" i want to add s to $url's http making it https://google.com.

I have little knowledge on PHP and if someone can explain to me how to go about doing this, this would be really helpful! thanks.

like image 902
Kevin Jung Avatar asked Mar 13 '11 12:03

Kevin Jung


People also ask

How to replace http with https in php?

$count = 1; $url = str_replace("http://", "https://", $url, $count);


1 Answers

$url = preg_replace("/^http:/i", "https:", $url); 
like image 77
Jakub Hampl Avatar answered Oct 20 '22 04:10

Jakub Hampl