Replace http With https in URL With PHP

Home»Software»Developer Tools»Replace http With https in URL With PHP
With more and more websites move to secure connection through HTTPS protocol, there may be a need to convert and replace all reference to unsecured HTTP protocol to SSL secured HTTPS protocol when referencing or linking to URLs.

When manipulating or dealing with URL in PHP programming language, it’s easier to replace all instances of http:// to https:// whenever required, such as when output HTML for web page, when validating the form, or when inserting or updating to the database.

To replace all references to http in PHP to https, use the preg_replace function with the following syntax:

$url = preg_replace("/^http:/i", "https:", $url);

By |Categories: Developer Tools|Tags: |0 Comments

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.Connect with LK through Tech Journey on Facebook, Twitter or Google+.

Pin It on Pinterest

Share This

Share This

Share this post with your friends!